Control Statments
Part A: Multiple Choice Questions
(1 Marks Each)
-
Which of the following is a declaration statement?
(a) int x;
(b) printf("%d", x);
(c) if(x>0)
(d) for(i=0; i<5; i++)
Ans:- (a) int x; -
Which library provides printf() and scanf()?
(a) conio.h
(b) stdio.h
(c) string.h
(d) math.h
Ans:- (b) stdio.h -
What does %f represent in printf()?
(a) Integer
(b) Character
(c) Float
(d) String
Ans:- (c) Float -
The correct syntax for declaring a constant is:
(a) int const MAX=100;
(b) const int MAX=100;
(c) constant int MAX=100;
(d) int MAX=constant 100;
Ans:- (b) const int MAX=100; -
Which function is used for unformatted input of a character?
(a) putchar()
(b) getchar()
(c) gets()
(d) scanf()
Ans:- (b) getchar() -
Which function displays a string followed by newline?
(a) puts()
(b) putchar()
(c) printf()
(d) getc()
Ans:- (a) puts() -
Which of the following is unsafe in modern C?
(a) printf()
(b) gets()
(c) scanf()
(d) puts()
Ans:- (b) gets() -
An expression statement always produces:
(a) condition
(b) loop
(c) value
(d) function
Ans:- (c) value -
Which is an example of a conditional statement?
(a) for
(b) while
(c) if
(d) continue
Ans:- (c) if -
Which loop executes at least once?
(a) for
(b) while
(c) do...while
(d) switch
Ans:- (c) do...while -
Which jump statement ends a function?
(a) break
(b) goto
(c) continue
(d) return
Ans:- (d) return -
What will break do in a loop?
(a) Skip next statement
(b) Exit loop immediately
(c) Jump to label
(d) Continue loop
Ans:- (b) Exit loop immediately -
What will continue do in a loop?
(a) Exit program
(b) Skip current iteration
(c) Jump to end
(d) Restart program
Ans:- (b) Skip current iteration -
Which statement allows multi-way branching?
(a) if
(b) for
(c) switch
(d) goto
Ans:- (c) switch -
Which symbol is used before variables in scanf()?
(a) $
(b) *
(c) &
(d) %
Ans:- (c) & -
Example of increment expression:
(a) x=5;
(b) x++;
(c) x=y+5;
(d) if(x>y)
Ans:- (b) x++; -
Which operator is used in declaration syntax?
(a) =
(b) ;
(c) ,
(d) :
Ans:- (a) = -
Which function is used to display a single character?
(a) putchar()
(b) puts()
(c) printf()
(d) getc()
Ans:- (a) putchar() -
What will printf("Age: %d",15); display?
(a) Age: %i
(b) Age: %f
(c) Age: 15
(d) Age: d
Ans:- (c) Age: 15 -
Which statement is used to jump to another labeled part of program?
(a) break
(b) continue
(c) return
(d) goto
Ans:- (d) goto
Part B: Very Short Answer Questions (1 Mark Each)
-
Write the syntax of variable declaration.
Ans:- datatype variable_name; (e.g., int x;) -
Which header file provides input/output functions in C?
Ans:- stdio.h -
What does %c format specifier represent?
Ans:- A single character. -
Give one example of a declaration statement.
Ans:- int a; -
Which function reads a string including spaces?
Ans:- gets() -
Which function is preferred instead of gets() in modern C?
Ans:- fgets() -
Give an example of an expression statement.
Ans:- x = y + 5; -
Which conditional statement allows multiple cases?
Ans:- switch statement. -
Write syntax of a for loop.
Ans:- for(initialization; condition; increment/decrement) { //code } -
Which statement is used to terminate a loop immediately?
Ans:- break;
Part C: Short Answer Questions (4 Marks Each)
Q1. Define declaration statement with one example.
Ans:- A declaration statement tells the compiler about the type of a variable.
Example: int age;
Q2. Differentiate between formatted and unformatted I/O statements.
Ans:-
-
Formatted I/O: Uses format specifiers. Example:
printf()
,scanf()
. -
Unformatted I/O: Works directly with characters/strings. Example:
getchar()
,putchar()
,gets()
,puts()
.
Q3. Explain the use of scanf() with an example.
Ans:- scanf()
is used to take input from the user.
Example: scanf("%d",&num);
Q4. What is the difference between putchar() and puts()?
Ans:-
-
putchar()
→ prints one character. -
puts()
→ prints a full string with a new line at the end.
Q5. Write the syntax and example of printf() function.
Ans:-
Syntax: printf("format specifier", variable);
Example: printf("Age: %d", 20);
Q6. Explain increment and decrement operators with examples.
Ans:-
-
Increment (
++
) increases value by 1. Example:x++;
-
Decrement (
--
) decreases value by 1. Example:x--;
Q7. Write syntax and example of if…else statement.
Ans:-
Syntax:
Example:
Q8. Differentiate between while loop and do...while loop.
Ans:-
-
while loop: checks condition first, then runs code.
-
do...while loop: runs code once first, then checks condition.
Q9. Write a short note on break and continue statements.
Ans:-
-
break
→ exits the loop immediately. -
continue
→ skips the current step and goes to the next loop cycle.
Q10. Why is gets() function unsafe in C?
Ans:- Because it does not check input size. This may cause buffer overflow, which is unsafe
Part D: Long Answer Questions (8 Marks Each)
Q1. Explain declaration statements in C with syntax and examples.
Ans:-
Declaration statements are used to create variables in C. They tell the compiler the type of data and name of the variable so that memory can be given.
Syntax:
Examples:
These help the compiler to know what type of value will be stored in each variable.
Q2. Describe formatted input/output functions (printf() and scanf()) with examples.
Ans:-
-
printf(): Used to display (print) output in a formatted way.
Example:
-
scanf(): Used to take (read) input in a formatted way.
Example:
Both functions use format specifiers like:
-
%d
→ integer -
%f
→ float -
%c
→ character -
%s
→ string
Q3. Differentiate between formatted and unformatted I/O statements in detail with examples.
Ans:-
Formatted I/O | Unformatted I/O |
---|---|
Uses format specifiers | Does not use format specifiers |
Works with integers, floats, characters, and strings | Works directly with characters/strings |
Examples: printf() , scanf() | Examples: getchar() , putchar() , gets() , puts() |
Examples:
Q4. Explain different types of control statements in C with suitable examples.
Ans:-
Control statements are used to control the flow of program execution. There are 3 types:
-
Conditional Statements (Decision making):
-
if
,if-else
,switch
Example:
-
-
Looping Statements (Repetition):
-
for
,while
,do...while
Example:
-
-
Jump Statements (Change program flow):
-
break
,continue
,goto
,return
Example:
-
Q5. What are jump statements in C? Explain break, continue, goto, and return with examples.
Ans:-
Jump statements are used to change the normal flow of a program.
-
break: Exits from a loop or switch immediately.
-
continue: Skips the current loop iteration and moves to the next one.
-
goto: Jumps to a labeled statement.
-
return: Ends a function and sends control back to the calling function.
No comments:
Post a Comment