Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
C Programming Language Standard
In this article, we will learn about the standards defined in the C programming language. These standards specify how programs should be compiled and executed as defined by the development community.
To understand this concept, let's examine a common C program that demonstrates standard compliance issues −
What is the C Programming Language Standard?
The C programming language standard defines the official specification for how C compilers should behave. It establishes the correct syntax, semantics, and behavior of C programs. The latest C standard is ISO/IEC 9899:2018, also known as C18, which was released in June 2018.
This standard defines crucial aspects such as −
- How programs should be compiled and executed
- Correct function declarations and definitions
- Behavior of built-in functions and operators
- Memory management rules
Syntax
The standard defines two correct ways to declare the main() function −
// No parameters
int main(void) {
/* program code */
return 0;
}
// With command-line arguments
int main(int argc, char *argv[]) {
/* program code */
return 0;
}
Example: Standard vs Non-Standard main() Function
Here's an example demonstrating the difference between standard and non-standard main() declarations −
#include <stdio.h>
/* Standard-compliant main() function */
int main(void) {
printf("This is a standard-compliant C program<br>");
printf("main() returns int and has proper return statement<br>");
return 0; /* Required by C standard */
}
This is a standard-compliant C program main() returns int and has proper return statement
Non-Standard Example (Avoid This)
The following code violates C standards −
#include <stdio.h>
/* Non-standard: void main() is not compliant */
void main() {
printf("This violates C standard<br>");
/* Missing return statement */
}
Note: Some compilers like Turbo C accept
void main(), but this is non-standard and should be avoided for portable code.
Key Points
- Always use
int main()instead ofvoid main() - Include
return 0;to indicate successful program termination - Follow standard syntax for better portability across different compilers
- Standard-compliant code ensures consistent behavior across platforms
Conclusion
Following C programming standards ensures your code is portable, reliable, and behaves consistently across different compilers and platforms. Always use int main() with proper return statements for standard-compliant programs.
