[go: up one dir, main page]

0% found this document useful (0 votes)
14 views4 pages

CS3251 DPT 1

The document outlines the structure of a C program, detailing various sections such as documentation, link, definition, global declaration, main function, and subprogram sections. It includes examples of keywords in C, a code snippet demonstrating the use of the comma operator, and a simple 'Hello, World!' program with explanations for each part. The final output of the examples is also provided.

Uploaded by

s.shaflafathima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

CS3251 DPT 1

The document outlines the structure of a C program, detailing various sections such as documentation, link, definition, global declaration, main function, and subprogram sections. It includes examples of keywords in C, a code snippet demonstrating the use of the comma operator, and a simple 'Hello, World!' program with explanations for each part. The final output of the examples is also provided.

Uploaded by

s.shaflafathima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS3251 – PROGRAMMING IN C

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

PART – B (16 MARKS)

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.

#include <stdio.h> // 1. Preprocessor Directive


int main() // 2. Main function - Entry point of the program
{
printf("Hello, World!\n"); // 3. Executable statement
return 0; // 4. Return statement
}
EXPLANATION:
1. Preprocessor Directive (#include <stdio.h>)
• #include <stdio.h> is a preprocessor directive that includes the standard
input-output library, which allows us to use printf().
2. Main Function (int main())
• The main() function is the starting point of any C program.
• Every C program must have a main() function.
3. Executable Statement (printf("Hello, World!\n");)
• The printf() function prints "Hello, World!" on the screen.
• The \n is a newline character that moves the cursor to the next line.
4. Return Statement (return 0;)
• The statement return 0; indicates that the program ran successfully.
• 0 typically means "no errors".
FINAL OUTPUT :
Hello, World!

You might also like