Searching...
Monday, September 16, 2013

Compilation processing of c programming

3:05 PM


Basic elements of a c program
·         Preprocessor Commands
·         Functions
·         Variables
·         Statements & Expressions
·         Comments
Let us start first C program which will print the words “hello, Word!”.
#include <stdio.h>
int main()
{
   /* my first program in C */
   printf("Hello, World! \n");
  
   return 0;
}

There are many   parts of the program in above is given
1.At first  line of the program #include<stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to main compilation.
2.The second line int main() is the main function . The execution begins from here.
3. The next line /*….*/ is a area where compiler ignore compilation.  So we put some message or information inside the area.
4.In the next line printf() is another function which display or print any message put into the printf function.
5.The next line return 0; terminates the main() function and returns the value to 0.

Compile and execute your first c program
At first open your notepad and add the code given below
  
#include <stdio.h>
int main()
{
   /* my first program in C */
   printf("Hello, World! \n");
  
   return 0;
}
Now save the file as hello.c and open your command prompt and go to the directory where you have saved the file. Now type gcc hello.c and press enter to compile your code.If there is no error it give a a.out executable file.Now type a.out to execute your program.
$ gcc hello.c
$ ./a.out
Hello, World!
 
Now you can the the output “Hello, World!”  printed the screen







N.B confirm that the gcc compiler is in your path and that you are running it in the directory containing source file hello.c.



0 comments:

Post a Comment

Followers