This is a simple “Hello, World!” C program to display “Hello, World!” text on the computer screen or display device.
Typically, the best way to learn programming is by writing code. The first program beginners write is “Hello, World!” which is often used to illustrate the syntax of a programming language. You can take a look at the list of Hello World Programs in 300 Programming Languages to see how “Hello World” looks like in different programming languages.
Let’s take a look at how “Hello World” program looks in C.
Example 1: C Hello World Program
1 2 3 4 5 6 7 8 9 | //My first C Program #include <stdio.h> int main() { printf("Hello, World!"); return 0; } |
Output of C Program
1 | Hello, World! |
The first line of this program is a comment which is indicated by double forward slashes i.e. //
Then lines beginning with a hash sign (#) are directives read and interpreted by what is known as the pre-processor in C programming.
Every C program starts execution from the main() function regardless of where the function is actually located within the code.
The printf() is the standard c library function which prints the “Hello World” text on the computer screen.
Finally, the return 0; is the exit status of the program which causes the C program to terminate.
Example 2: C Hello World Program
1 2 3 4 5 | #include <stdio.h> int main(int argc, char** argv) { puts("Hello, World!"); } |
Output of C Program
1 | Hello, World! |