ADVERTISEMENT
Structure of C Program
Before we look at the basic parts of the programming language C, let’s quickly look at how a very simple C program is put together. This will help us in the next part.
Hello World Example
The following things make up a C program:
- Preprocessor Commands
- Functions
- Variables
- Statements and Expressions
- Comments
This is a simple code that will print Hello World.
#include <stdio.h>
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}C ProgrammingTake a look at the different parts of the program above:
Line 1: It tells the C compiler to include the stdio.h file before it starts to compile the code in the first line of the program, which is called #include <stdio.h>.
Line 2: That line, int main() is the program’s main function. It’s where everything begins.
Line 3: The compiler will not use the next line, /*…*/. The code calls these lines comments for that reason.
Line 4: Another function in C, printf() is used to show the message “Hello, World!” on the screen.
Line 5: The function main() ends with the line return 0; which returns the value 0.