C- Programming Question Bank
Section 1: Fundamentals (Variables, Data Types,
Operators, Expressions)
1. Explain the difference between ++i and i++ with a suitable
example.
2. Evaluate the following expression and show each step:
a+b*c/d-e%f
where a=10, b=20, c=15, d=5, e=12, f=4.
3. Identify the type and value of the expression:
(x > y) ? x : y
Assume x = 8, y = 5.
4. What is the output of the following code? Justify your
answer.
c
#include <stdio.h>
int main() {
int a = 5, b = 3;
printf("%d\n", a & b);
printf("%d\n", a | b);
return 0;
}
Section 2: Branching Structures (if, if-else, switch,
break, continue)
5. Write a program to check if a year is a leap year or not
using if-else.
6. Write a program to input a character and check if it is a
vowel or consonant using switch.
7. What is the purpose of break and continue? Give an example for
each.
8. Correct the following code and explain the error:
c
#include <stdio.h>
int main() {
int marks = 85;
switch(marks) {
C- Programming Question Bank
case 75: printf("Distinction"); break;
case 60: printf("First Class"); break;
default: printf("Pass");
}
return 0;
}
Section 3: Loops (while, do-while, for, nested loops)
9. Write a program to print the multiplication table of a
number n using a for loop.
10. Write a program to find the factorial of a number using
a while loop.
11. Write a program to print the following pattern using
nested loops:
*
**
***
****
12. Differentiate between for, while and do-while loops with
an example.
Section 4: Arrays and Strings
C- Programming Question Bank
13. Write a program to find the smallest number in an
array of 10 integers.
14. Write a program to read and print a string
using gets() and puts().
15. Write a program to concatenate two strings without
using strcat().
16. Write a program to find the length of a string without
using strlen().
17. Write a program to multiply two 2x2 matrices and print
the result.
18. Explain the following string functions with examples:
o strcat()
o strlen()
o strrev()
Section 5: Problem Solving & Output Tracing
19. Trace the output of the following code:
#include <stdio.h>
int main() {
int i, j;
for(i = 1; i <= 3; i++) {
for(j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
20. Write a program to calculate the sum of the series:
1 + 1/2 + 1/3 + ... + 1/n