Chapter 1 LQ
Chapter 1 LQ
INTRODUCTION TO PROGRAMMING
1. Discuss the main parts of the structure of a C Program.
Definition:
“How a C program is built, arranged and organized is called the structure of a C program.”
The sequence of statements in the program should be according to the sequence in which we want
our program to be executed.
Sections/ Parts of the C program
A program is divided into different sections. Each code has a similar outline. There are three main
sections to a basic C program which are as follows:
(i) Link Section:
This part of the code is used to declare all the header files that will be used in the program. While
writing C programs, we extensively use built-in functions and header files are included in which these
functions are declared. The “include” keyword is used to include a header file in our program. The
include statement is always written at the top of the program.
Syntax:
#include<header filer name>
Example:
#include<stdio.h>
(ii) Main section:
It consists of the main function. Every C program must contain the main function because the execution
of the C program starts from it.
(iii) Body of a main function:
It contains the actual code to be executed. It starts from left curly brace “{“ and ends with right curly
brace “}”.
Example:
#include<stdio.h>
Int main( )
{
printf(“Hello Pakistan”);
return 0;
}
Section Explanation
Link section #include<stdio>
Main section int main
Body of the main {
function printf(“Hello Pakistan”);
return 0;
}
2. Describe Purpose and Syntax of Comments in C Programs. Also explain their types.
Comments:
“The statements in a program that are ignored by the compiler and do not get executed are called
comments.”
Usually, comments are written in natural language like in English language to provide description of
our code. We do not want these statements to be executed, because it may cause syntax error as the
statements are written in natural language.