HTML/JavaScript

Notes On Basic Structure Of C

                                                                



 C Program Mainly Consist Of:

  • Preprocessor commands
  • Functions
  • Variables
  • Statement & Expression
  • Comments
  • Let's Understand Our Code :
    • #include<stdio.h> : It’s a pre-processor command. It means we want to include stdio.h header file in our program. Stdio.h stands for standard input-output. It is a library in C that contains many function definitions such as ‘printf()’, scanf() etc.
    •  int main() : main is a function in C language. Execution of every C program starts from main() function. int before main means that the function will return an integer. main function is called by OS.
    • {}: Curly braces enclose the body of main() function.
    • printf(“Hello World\n”); : print() is a function defined in stdio.h header file and this function displays whatever is written inside its brackets on the screen.
    • return 0; : As we know that main function returns an integer value (int main()), therefore we are returning 0 here. return is a keyword which is used to return some value from a function. Returning 0 indicates that our program has been run successfully and we terminate our main function with this return statement.
    So, Here Is The Other Program To Add  Two Number :
                 
                                               



    Now, We'll Understand "How The C program Is Executed" :

     To check all the files which are made during the execution progress of a C program? Type this command in VS Code terminal: gcc –Wall –save-temps (filename.c) –o (desired_filename) and then press enter. After that, all the files which are created during execution progress will be shown up.

    Steps Including In Execution Of C Program Are :

    Pre-processing -> Compilation -> Assembly -> Linking.


    • Pre-Processing: In this process, comments are removed, macros are expanded and #include files are included.

    ·       Extension of pre-processed file is (.i)


    • Compiling: In this process, the pre-processed file is converted into assembly instructions.

    ·       Extension of assembly instruction file is (.s)


    • Assembly: Assembly instructions are then converted into machine language instructions.

    ·       Extension of machine instruction file is (.o)


    • Linking : In this process all object file i.e. (.o) files are converted to executable i.e. (.exe) program.


    That’s how the execution of the C program occurs.

    Code Written In The Video :

    #include <stdio.h>
    int main()
    {
        int ab;
        printf("Enter the value of a\n");
        scanf("%d", &a);
        printf("Enter the value of b\n");
        scanf("%d", &b);
        printf("The sum of the numbers is %d"a+b);
        return 0;
    }


    #include<stdio.h>
    int main()
    {
       printf("Welcome To Coding Champ");
        return 0;
    }                                                                                          

    Post a Comment

    0 Comments