Example of C Program

Example of C program is provided on this page.

A c program can be written with empty main() function and nothing else but that wouldn't provide any usefulness for a beginner.

With this example C program you will know the basic structure of C program.

Example of C Program

example of c program

The most famous example of a c program is printing "Hello World!" on console (terminal).

#include <stdio.h>
int main()
{
	printf("Hello World!");
	return 0;
}

Let us understand quickly which line does what.

#include <stdio.h> line tells the compiler to include contents of a file named stdio.h to current C program.

If you don't know what a compiler is, it is another program which reads this C program and replaces this line with the contents of stdio.h.

int is a basic data type.

main() is name of function, and this function will return a value of type int, currently returning 0.

The main part of this program is printf("Hello World!");.

printf() is a function defined in the file stdio.h, thats why we need to include contents of stdio.h to our program.

By now it is obvious, the use of printf() function is to print strings or data to terminal.

The example c program concludes here.

If you found this article please share it on any platform you like, it would be great help to this website and other readers like you.

Thank you for reading.

Comments