Programming In C, main() function, global and local variables, Comments in C Language
Question 1. Describe the purpose of the main() function and the body of main() function
Ans: Every C program must have the function main() which is the first section to be executed when the program runs. The word void before the function main() means that this function does not return a value and the second void inside the brackets means it does not have any argument. When we run a program the main() function is always executed first no matter where it appears in the program.
The body of main() Function.
The body of the function main() is surrounded by braces {}.
The left brace indicates the start of the body of the function
and the right brace indicates the end of the body of the function.
Question 2: Define global and local variables.
Ans: Variables are used in C program to store values.
Global Variables: Global variables are declared before the main() function. These variables are used any where in the program.
Local Variables: are declared within main() function and are used only within a function in which they are declared.
Comments in C Language
Question 3: Differentiate between single line and multiline comment.
Ans: Comments are added in programs when a fact is necessary to be brought to the attention of program’s reader. Generally, programmers write comments at the beginning of the program explaining the reader what the program is intended to achieve.
There are two types of comments.
Single line comments.
Multiple Line comments.
Single line comments
The // is used as single line comment. The syntax if single comment is // comment.
e.g.:
g.:/ Programmer: M.Sajjad Heder
Multiple Line comments
The /* …… */ is used for multiple line comments.
e.g:
g:/*Programmer: M.Sajjad Heder
Programming Language: */
Comments
Post a Comment