First C Program
Syntax
#include <stdio.h>
int main() {
printf("Hello, world!");
return 0;
}
Example
The following code is an example of a simple "Hello, world!" program:
#include <stdio.h>
int main() {
printf("Hello, world!");
return 0;
}
Output
When executed, the above code will output:
Hello, world!
Explanation
A C program starts execution with the main()
function. The stdio.h
library provides functionality for input and output operations.
In the example, printf()
is being used to output the string "Hello, world!". printf()
is a function that belongs to the stdio.h
library. The return 0;
statement indicates that the main()
function has finished executing.
Use
The "Hello, world!" program is a simple example used to demonstrate basic programming concepts, such as input/output operations, functions, and control structures. It is considered a standard starting point for learning a new programming language.
Important Points
- All C programs must have a
main()
function, which is the entry point of the program. - Header files, such as
stdio.h
, provide a set of standard functions and constants that can be used in C programs. - The
printf()
function is used to output data to the console. - The
return
statement is used to exit the function and return a value to the calling function or operating system.
Summary
The "Hello, world!" program is a basic example of a C program used to demonstrate basic programming concepts. Understanding the syntax and use of basic C programming constructs, such as functions, libraries, and input/output operations, is essential for developing more complex applications.