Your First C program !!

avatar

Hey there! Do you want to learn programming ? If so then do go through this post. This is one of the most basic program that we can have and you may even say that this is your first step towards learning any programming language. Here is the program:

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

Wait a minute...! What is all of this ? Don't worry, there is explanation to each and every line. Let's go step by step:

  1. "#include" is known as a preprocessor directive. It is the first line of any C program. It tells the "compiler" to add/include everything which is there in "stdio.h" to our code. Now, you may wonder, why do need to include the "things" to our code? We will see that.
  2. The next line says "int main()". Now, any C program executes from the main function. That is why it is one of the most important statements in C. The "int" is telling that the "main()" must return some kind of integer value. It is the return type of the function mainNow, you may get an idea after looking at the code.
  3. "{}" or curly brackets. Everything inside this "{}" is the body of the function "main".
  4. The next line is printf("Hello World"). This "printf()" is coming from "stdio.h" library. The line does exactly what you are thinking. It prints the text "Hello World". This is actually a string (inside double inverted commas).
  5. In the end comes the "return 0" statement. This means that the value that is "returned" to the function is 0 (Note that the return type of main function is int).

Best of luck for your programming career!


THANKS FOR VISITING!


Posted with STEMGeeks



0
0
0.000
0 comments