Skip to main content

2. First C Program

 

First C Program

As when learning any new language, the place to start is with the classic "Hello World!" program :

#include <stdio.h>

int main()
{
   printf("Hello World!\n");
   return 0;
}

Let's break down the code to understand each line :

  • #include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h.
  • int main() The main() function is the entry point of every program in C language.
  • printf() The printf() function is used to print data on the console.
  • \n The \n escape sequence outputs a always newline character. Escape sequences always begin with a backslash \.
  • The semicolon ; indicates the end of the statement. Each statement must end with a semicolon.
  • return 0 The return 0 statement, returns execution status to the OS. The value 0 is used for successful execution and 1 for unsuccessful execution.

Comments