The Wayback Machine - https://web.archive.org/web/20240827225216/https://www.geeksforgeeks.org/c-programming-language-standard/
Open In App

C Programming Language Standard

Last Updated : 25 Aug, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Introduction:

The C programming language has several standard versions, with the most commonly used ones being C89/C90, C99, C11, and C18.

  1. 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 features that are still used in modern C programming, including data types, control structures, and the standard library.
  2. C99 (ISO/IEC 9899:1999) introduced several new features, including variable-length arrays, flexible array members, complex numbers, inline functions, and designated initializers. This standard also includes several new library functions and updates to existing ones.
  3. C11 (ISO/IEC 9899:2011) introduced several new features, including _Generic, static_assert, and the atomic type qualifier. This standard also includes several updates to the library, including new functions for math, threads, and memory manipulation.
  4. C18 (ISO/IEC 9899:2018) is the most recent standard and includes updates and clarifications to the language specification and the library.

When writing C code, it’s important to know which standard version is being used and to write code that is compatible with that standard. Many compilers support multiple standard versions, and it’s often possible to specify which version to use with a compiler flag or directive.

Here are some advantages and disadvantages of using the C programming language:

Advantages:

  1. Efficiency: C is a fast and efficient language that can be used to create high-performance applications.
  2. Portability: C programs can be compiled and run on a wide range of platforms and operating systems.
  3. Low-level access: C provides low-level access to system resources, making it ideal for systems programming and developing operating systems.
  4. Large user community: C has a large and active user community, which means there are many resources and libraries available for developers.
  5. Widely used: C is a widely used language, and many modern programming languages are built on top of it.

Disadvantages:

  1. Steep learning curve: C can be difficult to learn, especially for beginners, due to its complex syntax and low-level access to system resources.
  2. Lack of memory management: C does not provide automatic memory management, which can lead to memory leaks and other memory-related bugs if not handled properly.
  3. No built-in support for object-oriented programming: C does not provide built-in support for object-oriented programming, making it more difficult to write object-oriented code compared to languages like Java or Python.
  4. No built-in support for concurrency: C does not provide built-in support for concurrency, making it more difficult to write multithreaded applications compared to languages like Java or Go.
  5. Security vulnerabilities: C programs are prone to security vulnerabilities, such as buffer overflows, if not written carefully.
    Overall, C is a powerful language with many advantages, but it also requires a high degree of expertise to use effectively and has some potential drawbacks, especially for beginners or developers working on complex projects.

Importance:

important for several reasons:

  1. Choosing the right programming language: Knowing the advantages and disadvantages of C can help developers choose the right programming language for their projects. For example, if high performance is a priority, C may be a good choice, but if ease of use or built-in memory management is important, another language may be a better fit.
  2. Writing efficient code: Understanding the efficiency advantages of C can help developers write more efficient and optimized code, which is especially important for systems programming and other performance-critical applications.
  3. Avoiding common pitfalls: Understanding the potential disadvantages of C, such as memory management issues or security vulnerabilities, can help developers avoid common pitfalls and write safer, more secure code.
  4. Collaboration and communication: Knowing the advantages and disadvantages of C can also help developers communicate and collaborate effectively with others on their team or in the wider programming community.

The idea of this article is to introduce C standard. 

What to do when a C program produces different results in two different compilers? 
For example, consider the following simple C program. 

C




void main() {  }


The above program fails in GCC as the return type of main is void, but it compiles in Turbo C. How do we decide whether it is a legitimate C program or not? 

Consider the following program as another example. It produces different results in different compilers. 

C




// C++ Program to illustrate the difference in different
// compiler execution
#include <stdio.h>
int main()
{
    int i = 1;
    printf("%d %d %d\n", i++, i++, i);
    return 0;
}


2 1 3 - using g++ 4.2.1 on Linux.i686
1 2 3 - using SunStudio C++ 5.9 on Linux.i686
2 1 3 - using g++ 4.2.1 on SunOS.x86pc
1 2 3 - using SunStudio C++ 5.9 on SunOS.x86pc
1 2 3 - using g++ 4.2.1 on SunOS.sun4u
1 2 3 - using SunStudio C++ 5.9 on SunOS.sun4u

Source: Stackoverflow
Which compiler is right?
The answer to all such questions is C standard. In all such cases, we need to see what C standard says about such programs.

What is C standard? 
The latest C standard is ISO/IEC 9899:2018, also known as C17 as the final draft was published in 2018. Before C11, there was C99. The C11 final draft is available here. See this for a complete history of C standards.

Can we know the behavior of all programs from C standard? 
C standard leaves some behavior of many C constructs as undefined and some as unspecified to simplify the specification and allow some flexibility in implementation. For example, in C the use of any automatic variable before it has been initialized yields undefined behavior and order of evaluations of subexpressions is unspecified. This specifically frees the compiler to do whatever is easiest or most efficient, should such a program be submitted.

So what is the conclusion about above two examples? 
Let us consider the first example which is “void main() {}”, the standard says following about prototype of main().

The function called at program startup is named main. The implementation 
declares no prototype for this function. It shall be defined with a return
type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names
may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;10) or in some other implementation-defined manner.

So the return type void doesn’t follow the standard, and it’s something allowed by certain compilers.

Let us talk about the second example. Note the following statement in C standard is listed under unspecified behavior.  

The order in which the function designator, arguments, and 
subexpressions within the arguments are evaluated in a function
call (6.5.2.2).

What to do with programs whose behavior is undefined or unspecified in standard? 
As a programmer, it is never a good idea to use programming constructs whose behavior is undefined or unspecified, such programs should always be discouraged. The output of such programs may change with the compiler and/or machine.

 



Previous Article
Next Article

Similar Reads

Difference Between C Language and LISP Language
C Language: C is the procedural Programming language. It was designed to be compiled using a compiler. The Language has small and fixed number of keywords like if/else, for, while,.. etc. We can use more than one assignment that may be used in one statement in this language. Functions are also used here, it can return values that can be ignored, wh
2 min read
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, flexible array members, complex numbers, and new keywo
8 min read
Introduction to the C99 Programming Language : Part II
In this article, we are going to discover some more interesting additions to C89 which gave us C99 standard: Variable Argument Lists: C99 brings out a small changes to the preprocessor. Macros can accept a variable number of arguments. These Macros are indicated by ellipsis (...) in their declaration. These Variable Arguments are represented by the
4 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 complex arithmetic fenv.h fenv.h gives access to flo
3 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 style, these features make C language suitable for sys
3 min read
A C Programming Language Puzzle
Give a = 12 and b = 36 write a C function/macro that returns 3612 without using arithmetic, strings and predefined functions. We strongly recommend you to minimize your browser and try this yourself first. Below is one solution that uses String Token-Pasting Operator (##) of C macros. For example, the expression "a##b" prints concatenation of 'a' a
1 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&amp;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 language B was now used for improving the UNIX system
3 min read
Introduction to C++ Programming Language
C++ is a general-purpose programming language that was developed as an enhancement of the C language to include object-oriented paradigm. It is an imperative and a compiled language.  C++ is a high-level, general-purpose programming language designed for system and application programming. It was developed by Bjarne Stroustrup at Bell Labs in 1983
7 min read
Opening Modes in Standard I/O in C/C++ with Examples
Pre-requisites: File Handling in C++ So far the operations using the C program are done on a prompt/terminal that is not stored anywhere. But in the software industry, most of the programs are written to store the information fetched from the program. One such way is to store the fetched information in a file. Different operations that can be perfo
13 min read
Standard Deviation in C
Standard deviation is a statistical metric generally used to understand the distribution in a dataset. In this article, we will learn to write a C program to calculate the Standard deviation. What is the Standard Deviation?The standard deviation of given data is the extent to which the individual data items differ from the mean of the given data. M
2 min read
ANSI C - C89 Standard
The C programming language, developed in the early 1970s by Dennis Ritchie at Bell Labs, quickly gained popularity due to its efficiency, portability, and flexibility. However, C variations and extensions by different compiler vendors led to compatibility issues. To address this, the American National Standards Institute (ANSI) formed a committee,
5 min read
C 17 Standard
C 17 standard, officially known as ISO/IEC 9899:2018, is the most recent revision of the C programming language standard, it was finalized in 2017 and published in June 2018. It is often referred to as C 18 due to its publication year, this standard is a direct successor to C11 (ISO/IEC 9899:2011) and focuses on refining the language by addressing
3 min read
Learn Programming Languages- List of 11 Popular 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. It is an essential part of software development because it creates a communication bridge between humans and computers. Now, if you are a beginner who wants to learn, search the internet, you w
9 min read
fgets() and gets() in C language
For reading a string value with spaces, we can use either gets() or fgets() in C programming language. Here, we will see what is the difference between gets() and fgets(). fgets() The fgets() reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read, the newline character
3 min read
isxdigit() function in C Language
isxdigit() function in C programming language checks that whether the given character is hexadecimal or not. isxdigit() function is defined in ctype.h header file. Hexadecimal equivalent of Decimal Numbers: Hexadecimal: 0 1 2 3 4 5 6 7 8 9 A B C D E F Decimal: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Syntax: char isxdigit( char x); Examples: Input : A
2 min read
isupper() function in C Language
isupper() function in C programming checks whether the given character is upper case or not. isupper() function is defined in ctype.h header file. Syntax : int isupper ( int x ); Examples: Input: A Output: Entered character is uppercase character Input: a Output: Entered character is not uppercase character Input: 1 Output: Entered character is not
2 min read
isalnum() function in C Language
isalnum() function in C programming language checks whether the given character is alphanumeric or not. isalnum() function defined in ctype.h header file. Alphanumeric: A character that is either a letter or a number. Syntax: int isalnum(int x); Examples: Input : 1 Output : Entered character is alphanumeric Input : A Output : Entered character is a
2 min read
trunc() , truncf() , truncl() in C language
All three functions are used to remove digits after decimal point and return the modified decimal number. trunc() : Truncates a double value after the decimal point and gives the integer part as the result. The return value and the arguments are of the type double. Syntax : double trunc(double x); Parameters: x :It takes a double value as an input
4 min read
How to clear console in C language?
It is one of the basic need a program may required i.e clear the console during execution time. Need of a clear console screen : A console screen must be cleared once its stated objectives have been completed. A user also needs a clear screen for new data. Like any other language, C offers a variety of ways to clear the console screen. The clear sc
7 min read
Assigning multiple characters in an int in C language
Consider the following C program. #include &lt;stdio.h&gt; int main(void) { int a = 'd'; printf(&quot;%d\n&quot;, a); /*OUTPUT - 100 (ASCII Code for character d)*/ int b = 'dd'; printf(&quot;%d&quot;, b); /*OUTPUT - 25700 (Explanation in detail given below)*/ return 0; } Output : 100 25700 We can easily guess that the output for 'd' is 100 as 100 i
1 min read
Difference between Java and C language
Here are some of the differences between Java and C language. C is much faster than Java Java is slower than C due to overhead. C Java C was developed by Dennis M. Ritchie between 1969 and 1973.Java was developed by James Gosling in 1995.C is a Procedural Programming Language.Java is Object-Oriented language.C is more procedure-oriented.Java is mor
3 min read
Similarities and Differences between Ruby and C language
Similarities between Ruby and C There are many similarities between C and Ruby, and some of them are: Like C, in Ruby also… A programmer is able to program procedurally if they like to do. But still, behind the scenes, it will be object-oriented.Both the languages have the same operators, for example, compound assignment and bitwise operators. But
3 min read
Draw a smiley face using Graphics in C language
Prerequisite: graphics.h, How to include graphics.h in CodeBlocks? The task is to write a C program to draw a smiley face using graphics in C.To run the program we have the include the below header file: #include &lt;graphic.h&gt; Approach: We will create a Smiley Face with the help below functions: fillellipse(int x, int y, int x_radius, int y_rad
2 min read
Security issues in C language
C is a very powerful and popular programming language. It was first developed in the 1970s. C language is used in programming Network drivers, Interpreters, and Compilers, etc.Even though the C language is widely used in different systems still it has many security flaws associated with it. This article focuses on discussing security vulnerabilitie
12 min read
Shopping Cart Project Using C Language
Online Shopping applications are one of the favorite applications out of all online applications. It is a very much used application in everyone's life. So, Let's try to create a Shopping cart using C language which can perform basic tasks for us. The functionality of the Shopping Cart Although online Shopping has many functionalities we can't incl
11 min read
Test Cases For Signup Page Using C Language
Prerequisite: Structure in C In this article, we are going to check on how to check test cases for the signup page using C language. The signup page is where we enter data to create our account on any of the websites or applications. A test case is a document that contains various sets of data, conditions to be performed, and the expected result fo
6 min read
Signals in C language
Prerequisite : Fork system call, Wait system call A signal is a software generated interrupt that is sent to a process by the OS because of when user press ctrl-c or another process tell something to this process. There are fix set of signals that can be sent to a process. signal are identified by integers. Signal number have symbolic names. For ex
5 min read
Difference between %d and %i format specifier in C language
A format specifier is a special character or sequence of characters used to define the type of data to be printed on the screen or the type of data to be scanned from standard input. A format specifier begins with a '%' character followed by the sequence of characters for different types of data. In short, it tells us which type of data to store an
3 min read
lvalue and rvalue in C language
lvalue:- lvalue simply means an object that has an identifiable location in memory (i.e. having an address). In any assignment statement "lvalue" must have the capability to store the data.lvalue cannot be a function, expression (like a+b) or a constant (like 3 , 4 , etc.). L-value: "l-value" refers to memory location which identifies an object. l-
4 min read
Difference between while(1) and while(0) in C language
Prerequisite: while loop in C/C++ In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The boolean condition is either true or false. while(1) It is an infinite loop which will run till a break statement is issued explicitly. Interestingly not
3 min read
Article Tags :