Introduction To The C99 Programming Language : Part I

Skip to content geeksforgeeks
  • Courses
    • DSA Courses
    • Programming Languages
  • Tutorials
    • Python Tutorial
      • Python Loops and Control Flow
    • Java
      • Java Interview Questions
      • Java Quiz
      • Advance Java
    • Programming Languages
    • System Design
    • Interview Corner
    • Computer Science Subjects
    • DevOps
    • Linux
    • Software Testing
    • Databases
    • Android
    • Excel
    • Mathematics
  • DSA
    • Data Structures
    • Algorithms
      • Analysis of Algorithms
      • Searching Algorithms
      • Sorting Algorithms
    • Practice
      • Company Wise Coding Practice
      • Practice Problems Difficulty Wise
      • Language Wise Coding Practice
      • Curated DSA Lists
    • Company Wise SDE Sheets
    • DSA Cheat Sheets
    • Puzzles
  • Data Science
    • Data Science Packages
    • Data Visualization
    • Data Analysis
  • Web Tech
    • Web Development Using Python
      • Django
      • Flask
    • Cheat Sheets
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App Introduction to the C99 Programming Language : Part I Last Updated : 10 Apr, 2023 Summarize Comments Improve Suggest changes Like Article Like Save Share Report Follow

Introduction:

C99 is a standardized version of the C programming language that was published in 1999 by the International Organization for Standardization (ISO). It introduced a number of new features and improvements over the previous C89 standard, including support for variable-length arrays, flexible array members, complex numbers, and new keywords such as inline and restrict.

In this first part of the introduction to C99 programming language, we will cover some of the key features and improvements that were introduced in C99.

1.Variable-Length Arrays (VLAs)

C99 introduced support for variable-length arrays (VLAs), which allows arrays to be declared with a length that is determined at runtime rather than at compile time. This can be useful in situations where the size of an array is not known until the program is executed. The syntax for declaring a VLA is similar to that of a regular array, but with empty brackets indicating that the size is not known until runtime:

C

void foo(int n) { int array[n]; // ... }

2.Flexible Array Members (FAMs)

Flexible array members (FAMs) are another new feature in C99 that allows arrays to be declared as the last member of a struct with an unspecified size. This can be useful in situations where a struct needs to have a variable-sized array as one of its members. The syntax for declaring a FAM is similar to that of a regular array, but with empty brackets indicating that the size is not specified:

Sure, here are some advantages, disadvantages, and recommended books for learning C99:

Advantages:

  1. Variable-length arrays allow for more flexible memory allocation at runtime.
  2. Flexible array members allow for variable-sized arrays to be part of a struct.
  3. Complex numbers provide built-in support for complex arithmetic.
  4. Inline functions and the restrict keyword can improve performance.
  5. Designated initializers and compound literals provide a more concise and expressive way to initialize data structures.

Disadvantages:

  1. Not all compilers fully support C99, so some features may not be available or may require compiler-specific extensions.
  2. The use of variable-length arrays and flexible array members can potentially lead to memory allocation issues if not used carefully.

Recommended books:

  1. “The C Programming Language” by Brian W. Kernighan and Dennis M. Ritchie
  2. “C Programming Absolute Beginner’s Guide” by Greg Perry and Dean Miller
  3. “C Programming: A Modern Approach” by K. N. King

Here is an example code with output demonstrating some of the features of C99:

C

#include <stdio.h> #include <complex.h> int main() { int n = 5; int array[n]; for (int i = 0; i < n; i++) { array[i] = i; printf("%d ", array[i]); } printf("\n"); struct foo { int x; int y[]; }; struct foo* f = malloc(sizeof(struct foo) + n * sizeof(int)); f->x = 42; for (int i = 0; i < n; i++) { f->y[i] = i; printf("%d ", f->y[i]); } printf("\n"); double complex z = 3.0 + 4.0*I; printf("Real part: %f\n", creal(z)); printf("Imaginary part: %f\n", cimag(z)); inline int add(int x, int y) { return x + y; } printf("Result: %d\n", add(2, 3)); int* restrict a = malloc(n * sizeof(int)); int* restrict b = malloc(n * sizeof(int)); for (int i = 0; i < n; i++) { a[i] = i; b[i] = n - i - 1; } int sum = 0; for (int i = 0; i < n; i++) { sum += a[i] * b[i]; } printf("Result: %d\n", sum); return 0; }

Output

0 1 2 3 4 0 1 2 3 4 Real part: 3.000000 Imaginary part: 4.000000 Result: 5 Result: 10

C99 is another name of ISO/IEC 9899:1999 standards specification for C that was adopted in 1999. This article mainly concentrates on the new features added in C99 by comparing with the C89 standard. In the development stage of the C99 standard, every element of the C language was re-examined, usage patterns were analyzed, and future demands were anticipated. C’s relationship with C++ provided a backdrop for the entire development process. The resulting C99 standard is a testimonial to the strengths of the original.

  1. Keywords added in C99:
    • inline: C99 adds the keyword inline which is applicable to functions. If we write inline datatype function_name (param) to any function it means that we are specifying the compiler to optimize calls to that function i.e. the function’s code will be expanded inline rather than called. Example:

C

// C program to demonstrate inline keyword #include <stdio.h> inline int maximum(int a, int b) { return a > b ? a : b; } int main() { int x = 5, y = 10; printf("Maximum of %d and %d is %d", x, y, maximum(x, y)); return 0; }

  • Note: Some Compilers show undefined reference to maximum(). This inline feature is used rarely as a keyword. The above program is equivalent to the following

C

#include <stdio.h> int main() { int x = 5, y = 10; printf("Maximum of %d and %d is %d", x, y, (x > y ? x : y)); return 0; }

Output:

Maximum of 5 and 10 is 10
  • Inline functions help us to create efficient code by maintaining a structured, function-based approach.
  • restrict: restrict is a type qualifier applicable only for pointers. A pointer qualified by restrict is initially the only means by which the object it points to can be accessed. Access to the object by another pointer can occur only if the second pointer is based on the first. We use restrict qualifier to restrict access to the object. These are primarily used as function parameters or in malloc(). The restrict qualifier never changes the semantics of the program.
  • _Bool Datatype: _Bool datatype was added in C99 standard which stores 0 and 1 values. _Bool is an integer type. Note: bool keyword in C++ and _Bool in C are different. _Bool is used rarely instead C99 defines a new header file stdbool.h which defines three macros bool, true and false.
  • _Complex: C99 adds support for performing operations on complex numbers through _Complex and _Imaginary keywords. These keywords provide better support for numerical programming. Types defined in _Complex:
    • float _Complex
    • double _Complex
    • long double _Complex
  • _Imaginary: As said above, C99 adds support for performing operations on complex numbers through _Complex and _Imaginary keywords. These keywords provide better support for numerical programming. Types defined in _Complex and _Imaginary:
    • float _Imaginary
    • double _Imaginary
    • long double _Imaginary
  1. Addition of Type Qualifiers: Another important aspect added in C99 is the introduction of long long and unsigned long long type modifiers. A long long int has a range of –(2^63 – 1) to +(2^63 –1). An Unsigned long long int has a minimal range starting from 0 to +(2^64 –1). This long long type allows 64-bit integers to support as a built-in type.
  2. Changes in Arrays: C99 added two important features to arrays:
    • Variable Length Arrays: In C89 standard, the array size has to be specified using integer constants at the array declaration and array size is fixed at compile time. In C99 standard, we can declare an array whose dimensions are specified by any integer expressions whose values known at run-time. This is called Variable Length Arrays(VLA).
    • Inclusion of Type Qualifiers: In C99, we can use the keyword static inside the square brackets during array declaration. This is only applied when array is declared in function parameters i.e Example:

C

int fun1(char arr[static 80]) { // code }

  • In the above example arr is always a pointer to an 80-element array i.e arr is guaranteed to point the starting element of the array of chars that contains atleast 80 elements. We can also use the keywords restrict, volatile and const inside the square brackets if that array is declared inside a function parameters. Keyword restrict specifies that the pointer is the sole initial means of access to the object. const states that the pointer always points to the same object. volatile is allowed, but it has no meaning. Example:

C

#include <stdio.h> void fun(int a[static 10]) { for (int i = 0; i < 10; i++) { a[i] += 1; printf("%d ", a[i]); } } int main() { int a[] = { 1, 2, 3, 4, 4, 4, 4, 4, 5, 5, 6, 7, 8, 9, 10 }; fun(a); }

  1. Single Line Comments: Single Line comments aren’t accepted in C89 standard. C99 standard introduces Single Line Comments which are used only when brief remarks are needed. These comments begin with // and runs to the end of the line. Eg:

C

// First Comment int a; // another comment

  1. Declaration of Identifiers: According to the C89 standard, all Identifiers should be declared at the start of the code block. If we need any other identifier at the middle, we can’t declare for that instance or time. We need to declare that at the start. C99 has changed this rule as we can declare identifiers whenever we need in a code. In simple, we can see this as:

C

#include <stdio.h> int main() { int i; i = 1; int j; // this declaration is invalid in C89 standard, but valid in C99 and C++ j = 3; }

author avsadityavardhan Follow Improve Previous Article Design Goals and Principles of Object Oriented Programming Next Article

Similar Reads

  • Introduction to the C99 Programming Language : Part I Introduction: C99 is a standardized version of the C programming language that was published in 1999 by the International Organization for Standardization (ISO). It introduced a number of new features and improvements over the previous C89 standard, including support for variable-length arrays, flex 8 min read
  • Introduction to the C99 Programming Language : Part III Kindly read Introduction to the C99 Programming Language (Part I) and Introduction to the C99 Programming Language (Part II) before reading this article. Addition of Library Functions: C99 provides some Additional Library functions listed below. Library Function Usage complex.h complex.h supports co 3 min read
  • Introduction to Programming Languages Introduction: A programming language is a set of instructions and syntax used to create software programs. Some of the key features of programming languages include: Syntax: The specific rules and structure used to write code in a programming language.Data Types: The type of values that can be store 13 min read
  • Control Structures in Programming Languages Control Structures are just a way to specify flow of control in programs. Any algorithm or program can be more clear and understood if they use self-contained modules called as logic or control structures. It basically analyzes and chooses in which direction a program flows based on certain paramete 3 min read
  • C Programming Language Tutorial In this C Tutorial, you’ll learn all C programming basic to advanced concepts like variables, arrays, pointers, strings, loops, etc. This C Programming Tutorial is designed for both beginners as well as experienced professionals, who’re looking to learn and enhance their knowledge of the C programmi 8 min read
  • Features of C Programming Language C is a procedural programming language. It was initially developed by Dennis Ritchie in the year 1972. It was mainly developed as a system programming language to write an operating system. The main features of C language include low-level access to memory, a simple set of keywords, and a clean styl 3 min read
  • Learn Free Programming Languages In this rapidly growing world, programming languages are also rapidly expanding, and it is very hard to determine the exact number of programming languages. Programming languages are an essential part of software development because they create a communication bridge between humans and computers. No 9 min read
  • C Programming Language Standard Introduction:The C programming language has several standard versions, with the most commonly used ones being C89/C90, C99, C11, and C18. C89/C90 (ANSI C or ISO C) was the first standardized version of the language, released in 1989 and 1990, respectively. This standard introduced many of the featur 6 min read
  • Print "GeeksforGeeks" in 10 different programming languages The most elementary part of learning any computer programming language is the ability to print a desired text on the screen or console. Thus, the task of this article is to guide programmers new to any of the 10 different languages discussed below, i.e. GO, Fortran, Pascal, Scala, Perl, ADA, Ruby, K 4 min read
  • A Categorical List of programming languages Programming languages are the formal language, with a set of instructions which provides the desired output. For implementing various algorithms in our machines we started using the Programming language. A set of specific instructions are used in programmable machines, rather than general programmin 7 min read
  • C Programming Interview Questions (2024) At Bell Labs, Dennis Ritchie developed the C programming language between 1971 and 1973. C is a mid-level structured-oriented programming and general-purpose programming. It is one of the oldest and most popular programming languages. There are many applications in which C programming language is us 15+ min read
  • C program to detect tokens in a C program As it is known that Lexical Analysis is the first phase of compiler also known as scanner. It converts the input program into a sequence of Tokens. A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.For Example: 1) Keyword 5 min read
  • Benefits of C language over other programming languages C is a middle-level programming language developed by Dennis Ritchie during the early 1970s while working at AT&T Bell Labs in the USA. The objective of its development was in the context of the re-design of the UNIX operating system to enable it to be used on multiple computers. Earlier the lan 3 min read
  • C Programming For Beginners - A 20 Day Curriculum! For the last 40-45 years, C is one of the most popular and highly recognized programming languages in the world. In fact, it is the first programming language of a huge number of individuals (including me!). Indeed, it is strongly recommended to start your programming journey with C language as it h 7 min read
  • What is COBOL(Common Business Oriented Language)? COBOL an acronym for Common Business Oriented Language is a computer programming language, which was designed for business use. COBOL was procedural in the beginning, but since 2002, COBOL became object-oriented. COBOL was developed by Conference of Data System Languages(CODASYL). COBOL is primarily 6 min read
  • Implement a Stack in C Programming Stack is the linear data structure that follows the Last in, First Out(LIFO) principle of data insertion and deletion. It means that the element that is inserted last will be the first one to be removed and the element that is inserted first will be removed at last. Think of it as the stack of plate 7 min read
  • Zig - A Brief Introduction As software systems naturally become more complex, the requirement for new programming languages that are able not only to get good performance but also to be safe and to be on a modern language level increases continuously. This landscape is where Zig resumes its place among venerable low level pro 13 min read
  • Commonly Asked C Programming Interview Questions | Set 2 This post is second set of Commonly Asked C Programming Interview Questions | Set 1What are main characteristics of C language? C is a procedural language. The main features of C language include low-level access to memory, simple set of keywords, and clean style. These features make it suitable for 3 min read
  • Design Goals and Principles of Object Oriented Programming The fundamental goal of dealing with the complexity of building modern software naturally gives rise to several sub-goals. These sub-goals are directed at the production of quality software, including good implementations of data structures and algorithms. The article focuses on discussing design go 13 min read
Article Tags :
  • C Language
  • Programming Language
Like three90RightbarBannerImg Explore More We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It ! Lightbox Improvement Suggest changes Suggest Changes Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal. geeksforgeeks-suggest-icon Create Improvement Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all. geeksforgeeks-improvement-icon Suggest Changes min 4 words, max CharLimit:2000

What kind of Experience do you want to share?

Interview Experiences Admission Experiences Career Journeys Work Experiences Campus Experiences Competitive Exam Experiences

Từ khóa » C99 C