CodersEditor Tutorials

CodersEditor Tutorials

  • Online IDE
  • Q&A
  • C Programming
  • Java
  • GraphQL.NET
  • System Software

›Introduction

C Programming

    Introduction

    • Overview
    • Installation & Setup
    • C Program Structure
    • Keywords & Identifiers
    • Data Types
    • Variables & Constants
    • Scope Rules
    • Storage Class
    • Standard Input and Output
    • Operators

    Control Flow/Decision Making

    • Overview
    • if Statement
    • if else Statement
    • Nested If statement
    • Switch Statement
    • Nested Switch Statement
    • Conditional Operators

    Loop

    • Loops Overview
    • While loop
    • For Loop
    • Do while
    • Nested Loops
    • Break
    • Continue Statement
    • Goto statement

    Arrays

    • Arrays
    • Multi Dimensional Arrays
    • Arrays & Functions

    Pointers

    • Pointers Basics
    • Pointers and Arrays
    • Pointers and Functions
    • Memory allocation

    Strings

    • String Basics
    • String Functions

    C Programming Examples

    • Basic Example 1

C Program Structure

This article explains the basic program structure of a C program and you can follow this structure for any C programs that you do.

Structure of a C program

Below is the structure for any C program. By writing C programs with this proper structure, the compilation errors can be avoided.

  • HEADER
  • MAIN()
  • VARIABLE DECLARATION
  • BODY
  • RETURN

Header Section

The header file is a file with the extension .h which includes function declaration and macro definition for C in-built library functions. stdio.h, stdlib.h, iostream.h, are some of the header files. Syntax: include

Main Method Declaration

The next part of a C program is to declare the main() function. The main () function is where the execution of the program gets started. It is the entry point of any C program.

Syntax : Int main()

Variable Declaration

The variable declaration refers to the variables that are to be used in the function. In the C program, no variable can be used without being declared before any operation in the function.

Syntax : int a;

Body Section

This section refers to the operations that are performed like printing, sorting, manipulations, searching, etc.

Return Statement

The last part is the return statement. The return statement returns the values from a function and the return value depends on the return type of the function. For example: for the void return type, there will be no return statement. For any other case, there will be a return statement and the return value will be based on the return type.

Let us look into an example with the basic structure of C programming and how to compile and run a program in coderseditor-online compiler.

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

The above program includes all the sections for a perfect C program structure.

Now you can compile and run the program by clicking on the Run program button on the top or by pressing Ctrl + F9.

OUTPUT

Hello World!

The program runs with no error and hence the output is displayed. Hope, at the end you have got a clear idea about the C program structure.

← Installation & SetupKeywords & Identifiers →
  • Structure of a C program
    • Header Section
    • Main Method Declaration
    • Variable Declaration
    • Body Section
    • Return Statement
CodersEditor Tutorials
CoderdEditor Developer Tools
CodersEditor Online EditorGit Flavoured Markup EditorFree Online JSON FormatterFind My IP Address Details
Tutorials
C ProgrammingJava
Copyright © 2021 CodersEditor.com