CodeSutraHub

C Program Structure

Before learning the structure of a C program, let us first understand the basic concepts of programming languages.

Programming Language

A programming language is a special language used to give instructions to a computer. Just as humans need a language to communicate with each other, a language is required to communicate with a computer. The language used to communicate with a computer is called a programming language. Giving instructions directly in machine language (which consists of only 0s and 1s) is very difficult, so we use programming languages. Programming languages are easy for humans to read and write.

Compiler in Programming Language

The compiler converts the instructions written in a programming language into machine language. Instructions written in C language must be converted into machine language using a compiler. For this purpose, we use a C compiler. There are many editors available to write C programs. These editors allow us to write, compile, and run C programs on a single platform. Examples include Visual Studio Code, Code::Blocks, etc. This means that to write, compile, run, and test a C program, we need an editor. You must download and install an editor that suits you.

Program in Programming Language

A program is a set of instructions given to a computer to perform a specific task. For example, if we want to create a program to generate students’ marks lists, we write instructions to: read students’ marks, calculate the marks, and print the result. Generally, a program takes input from the user (such as students’ marks), processes it, and produces output (such as a marks list).
input -> processing -> output

Syntax in Programming Language

Just as human languages have grammar rules to form sentences using words, programming languages also have rules to write programs. These rules are called syntax rules.

Keywords in Programming Language

In human languages, the meanings of words are predefined. Similarly, in programming languages, certain words are predefined. These predefined words are called keywords.

Identifiers in Programming Language

Along with the keywords provided by a programming language, programmers can create their own names while writing programs. These names are called identifiers.

Statements in Programming Language

Sentences written using keywords and identifiers, following syntax rules, are called statements.

C Program Structure

The following C program displays "Hello, Welcome to C World" on the screen


#include <stdio.h>

int main() {
    printf("Hello, Welcome to C World");
    return 0;
}
    
When this program is executed, the message "Hello, Welcome to C World" is printed on the screen.
It is okay if you do not understand how this program works right now. We will learn everything about it in the upcoming tutorials. (For now, just write this program and run it.)

Important Points to Consider Now

  • Every C program starts with int main() (you can also use void main()).
  • An opening brace { must be written after main(), and a closing brace } must be written at the end of the program.
  • printf("Hello, Welcome to C World"); and return 0; are statements.
  • Every statement ends with a semicolon ;.
  • The statement return 0; indicates to the operating system (OS) that the program has completed successfully.

So far, we have learned

  • What is a Programming Language?
  • What is a Compiler?
  • What is Syntax?
  • Structure of a C Program
In the next topic, we will learn about C Installation.

Below Video Explains Programming Languages