Home C Programming Tutorial Basic Structure of a C program

Basic Structure of a C program

by anupmaurya
3 minutes read

In this tutorial, you’ll learn about basic Structure of a C program, Comments, Compilation and execution and Receiving input from the user.

All c programs have to follow a basic structure. A c program starts with the main function and executes instructions presents inside it. Each instruction terminated with a semicolon(;)

There are some basic rules which are applicable to all the c programs:

  1. Every program’s execution starts from the main function.
  2. All the statements are terminated with a semi-colon.
  3. Instructions are case-sensitive.
  4. Instructions are executed in the same order in which they are written.

Comments

Comments are used to clarify something about the program in plain language. It is a way for us to add notes to our program. There are two types of comments in C:

  1. Single line comment: //This is a comment.
  2. Multi-line comment : /*This is multi-line comment*/

Comments in a C program are not executed and ignored.

Compilation and execution

A compiler is a computer program that converts a c program into machine language so that it can be easily understood by the computer.

A program is written in plain text. This plain text is a combination of instructions in a particular sequence. The compiler performs some basic checks and finally converts the program into an executable.

Library functions

C language has a lot of valuable library functions which is used to carry out a certain task; for instance, printf function is used to print values on the screen.

printf(“This is %d”,i);

// %d for integers

// %f for real values

// %c for characters

Receiving input from the user

In order to take input from the user and assign it to a variable, we use scanf function.

The syntax for using scanf:

scanf(“%d”,&i); // [This & is important]

& is the “address of” operator, and it means that the supplied value should be copied to the address which is indicated by variable i.

Thank you for reading, If you have reached so far, please like the article, It will encourage me to write more such articles. Do share your valuable suggestions, I appreciate your honest feedback!

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.