CS3251 DPT 1
CS3251 DPT 1
DPT -1
PART – A (2 MARKS)
1. List atleast any ten keywords in C language?
ANS: There are certain reserved words called keywords,that have standard and
predefined meaning in ‘C’ language. List as follows,
Int , float , char , double , if , else , while , for , return , void
2. What is the output of the following program ?
#include<stdio.h>
int main()
{
int i;
i = 1,2,3;
printf(“%d”, i);
return 0;
}
ANS: Explanation:
• The statement i = 1,2,3; is evaluated using the comma operator (,).
• The comma operator separates expressions but has left-to-right
associativity.
• i = 1 is evaluated first, so i is assigned the value 1.
• The remaining values 2, 3 are evaluated but not assigned to i.
• Finally, printf("%d", i); prints the value of i, which is 1.
FINAL OUTPUT IS 1
1. Discuss the structure of c program in detail and explain with simple hello
world program
ANS:
DOCUMENTATION SECTION:
The documentation section consists of a set of comment lines giving the
name of the program, the author and other details, which the programmer would
like to use later.
LINK SECTION:
The link section provides instructions to the compiler to link functions
from the system library such as using the #include directive.
DEFINITION SECTION:
The definition section defines all symbolic constants such using the
#define directive.
GLOBAL DECLARATION SECTION:
There are some variables that are used in more than one function. Such
variables are called global variables and are declared in the global declaration
section that is outside of all the functions. This section also declares all the user-
defined functions.
MAIN () FUNCTION SECTION:
Every C program must have one main function section. This section
contains two parts; declaration part and executable part.
DECLARATION PART:
The declaration part declares all the variables used in the executable
part.
EXECUTABLE PART:
There is at least one statement in the executable part. These two parts
must appear between the opening and closing braces. The program execution
begins at the opening brace and ends at the closing brace. The closing brace of the
main function is the logical end of the program. All statements in the declaration
and executable part end with a semicolon.
SUBPROGRAM SECTION:
If the program is a multi-function program then the subprogram
section contains all the user-defined functions that are called in the main ()
function. User-defined functions are generally placed immediately after the main ()
function, although they may appear in any order.
All section, except the main () function section may be absent when they are not
required.