More

    C Program Structure

    - Advertisement -

    The C program structure is so simple. A basic C program can have only a mandatory main function, which will work. In detail, let’s see the C program structure with a hello world C program.

    c program structure

    Hello World C Program

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

    C Program Structure

    The C program above prints hello world in the terminal, consisting of the main function and one operation in the main function.

    int main() //this is the main function
    {
        printf("Hello World'); //operation in the main function
    }

    Above the main function, we have the line #include<stdio.h> , this line is called the document section because we include a header file from the C program library.

    We can use // in C programs for a single line comment and /* */ for the multiline comments.

    // this is the example of single line comment
    
    /*
        This is the example of multiline comment, these
        comments are ignored by compiler.
    */

    Note that: Only the main function is mandatory in any C program all others are optional. If you don’t have a main function in your C program, it won’t compile.

    Look at the image below to have a good look at the structure of the C Program.

    structure of c program
    Structure of C program
    - Advertisement -

    Read More In C Language:

    - Advertisement -

    Recent Articles

    Leave A Reply

    Please enter your comment!
    Please enter your name here