Friday, 27 March 2020

Session 1 compilation , installation, structure of C program

C Compilation

The C source code needs to be "compiled", into machine language so that the CPU can actually execute the program as per the instructions given.  The compiler compiles the source codes into final executable programs. The most frequently used and free available compiler is the GNU C.

Installation on Linux

If you are using Linux or UNIX, then check whether GCC is installed on your system by issuing the following command

$ gcc -v

If gnu compiler is installed , then you will get the following message:
$ Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu

If gcc is not installed, install it from

https://gcc.gnu.org/install/



Structure of C Program

a) Comments Section

b) Pre processor Statements

      Header file Inclusion,  Macro Statements

c) global declaration section

d) main() function where the program execution begins

    The execution of the program begins at the opening brace '{' and ends       with  } the closing brace
      This has the local declaration of variables  used in the program
      The body of the program that has the Program Statements and Expressions

e) Return statement
     This refers to the return of the values from the function. The return vale depends on the return type of the function. A void function does not have a return statement

First C Program -> Hello.c

/* Author: s.Kalpalatha
Writes the words "Hai Hello, World!" on the screen
compile:  gcc hello.c -o hello
Run : ./hello
*/

#include<stdio.h>

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









No comments:

Post a Comment