Thursday, 16 March 2017

FIRST C PROGRAM

Lets start with our first c program example
Here is a simple c program which prints a simple "Hello world" message on the console.

  • #include<stdio.h>
  • int main()
  • {
  •        printf("Hello world \n");
  •        return 0;
  • }
The above program will print a simple "Hello world" message shown below.

You might be thinking what is that #include , stdio.h, main ,printf , return 0 for. SO.......
Lets have a look at the code.
  • #include
#include is a preprocessor directive. Both user and system header files are included using the preprocessing directive "#include".
  • stdio.h
"stdio.h" is a header file which stands for standard input output library. In order to use the "printf" function we need to include "stdio.h" header file. By including stdio.h we can use other functions like "scanf", "getc", "putc" and all. We'll look at it in later sections.
  • int main()
"int " is a Data type which refers to integer values. "main( )" is a function which is necessary in order to run any particular program. We'll come to functions and data types in later sections. Just remember that "int main( )" is a initial function which is required for any program to run and int defines the return type of that "main function". "main" function is the first function to be executed in any program.
  • printf("hello");
"printf" is a build in function which is used to display message on console or screen.
  • return 0
In main we have seen something about return type that return type is here we return 0 which is an integer value. "return 0" is mostly used in main function to specify that the program is working fine.
  • { } (curly braces), ; (semicolon)
"curly braces" are used to declare the scope of any function. The semicolon is used to define statement termination.

No comments:

Post a Comment