Sunday, August 31, 2025

Lesson 2 (Q&A)

 Control Statments


Part A: Multiple Choice Questions

(1 Marks Each)

  1. 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;

  2. Which library provides printf() and scanf()?
    (a) conio.h
    (b) stdio.h
    (c) string.h
    (d) math.h
    Ans:- (b) stdio.h

  3. What does %f represent in printf()?
    (a) Integer
    (b) Character
    (c) Float
    (d) String
    Ans:- (c) Float

  4. 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;

  5. Which function is used for unformatted input of a character?
    (a) putchar()
    (b) getchar()
    (c) gets()
    (d) scanf()
    Ans:- (b) getchar()

  6. Which function displays a string followed by newline?
    (a) puts()
    (b) putchar()
    (c) printf()
    (d) getc()
    Ans:- (a) puts()

  7. Which of the following is unsafe in modern C?
    (a) printf()
    (b) gets()
    (c) scanf()
    (d) puts()
    Ans:- (b) gets()

  8. An expression statement always produces:
    (a) condition
    (b) loop
    (c) value
    (d) function
    Ans:- (c) value

  9. Which is an example of a conditional statement?
    (a) for
    (b) while
    (c) if
    (d) continue
    Ans:- (c) if

  10. Which loop executes at least once?
    (a) for
    (b) while
    (c) do...while
    (d) switch
    Ans:- (c) do...while

  11. Which jump statement ends a function?
    (a) break
    (b) goto
    (c) continue
    (d) return
    Ans:- (d) return

  12. 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

  13. 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

  14. Which statement allows multi-way branching?
    (a) if
    (b) for
    (c) switch
    (d) goto
    Ans:- (c) switch

  15. Which symbol is used before variables in scanf()?
    (a) $
    (b) *
    (c) &
    (d) %
    Ans:- (c) &

  16. Example of increment expression:
    (a) x=5;
    (b) x++;
    (c) x=y+5;
    (d) if(x>y)
    Ans:- (b) x++;

  17. Which operator is used in declaration syntax?
    (a) =
    (b) ;
    (c) ,
    (d) :
    Ans:- (a) =

  18. Which function is used to display a single character?
    (a) putchar()
    (b) puts()
    (c) printf()
    (d) getc()
    Ans:- (a) putchar()

  19. What will printf("Age: %d",15); display?
    (a) Age: %i
    (b) Age: %f
    (c) Age: 15
    (d) Age: d
    Ans:- (c) Age: 15

  20. 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)

  1. Write the syntax of variable declaration.
    Ans:- datatype variable_name; (e.g., int x;)

  2. Which header file provides input/output functions in C?
    Ans:- stdio.h

  3. What does %c format specifier represent?
    Ans:- A single character.

  4. Give one example of a declaration statement.
    Ans:- int a;

  5. Which function reads a string including spaces?
    Ans:- gets()

  6. Which function is preferred instead of gets() in modern C?
    Ans:- fgets()

  7. Give an example of an expression statement.
    Ans:- x = y + 5;

  8. Which conditional statement allows multiple cases?
    Ans:- switch statement.

  9. Write syntax of a for loop.
    Ans:- for(initialization; condition; increment/decrement) { //code }

  10. 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:

if(condition) { //code } else { //code }

Example:

if(x>0) printf("Positive"); else printf("Negative");

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:

datatype variable_name;

Examples:

int age; // integer variable float marks; // decimal value variable char grade; // character variable

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:

printf("Name: %s, Age: %d", name, age);
  • scanf(): Used to take (read) input in a formatted way.
    Example:

scanf("%d", &age);

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/OUnformatted I/O
Uses format specifiersDoes not use format specifiers
Works with integers, floats, characters, and stringsWorks directly with characters/strings
Examples: printf(), scanf()Examples: getchar(), putchar(), gets(), puts()

Examples:

// Formatted I/O scanf("%d", &num); printf("Average = %f", avg); // Unformatted I/O char ch = getchar(); puts("Hello World");

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:

  1. Conditional Statements (Decision making):

    • if, if-else, switch
      Example:

    if(x > 0) printf("Positive"); else printf("Negative");
  2. Looping Statements (Repetition):

    • for, while, do...while
      Example:

    for(i=0; i<5; i++) printf("%d", i);
  3. Jump Statements (Change program flow):

    • break, continue, goto, return
      Example:

    for(i=0; i<10; i++) { if(i == 5) break; // loop stops when i=5 }

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.

  1. break: Exits from a loop or switch immediately.

    for(i=1;i<=5;i++) { if(i==3) break; printf("%d ",i); // prints 1 2 }
  2. continue: Skips the current loop iteration and moves to the next one.

    for(i=1;i<=5;i++) { if(i==3) continue; printf("%d ",i); // prints 1 2 4 5 }
  3. goto: Jumps to a labeled statement.

    goto label; printf("This will be skipped"); label: printf("This is goto statement");
  4. return: Ends a function and sends control back to the calling function.

    int sum(int a, int b) { return a + b; }

No comments:

Post a Comment

lesson 3 Array (Hindi medium Q&A)

  Array (ऐरे) – प्रश्नोत्तर  Part A: Multiple Choice Questions (1 अंक प्रत्येक) Q1. एक ऐरे (Array) किन प्रकार के मान (values) को संग्रहीत...