Question Bank Theory Answers C Programming
Question Bank Theory Answers C Programming
Q2) Explain the usage of break, labelled break, continue and labelled continue
statements?
Ans. In C programming, break and continue are control flow statements used to
alter the normal execution of loops or switch statements. While labelled break and
labelled continue are not directly supported in C, similar behavior can be achieved
using the goto statement. Below are detailed explanations of each
1. break Statement
The break statement is used to:
• Exit a for, while, or do-while loop prematurely.
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
2
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
3
Output:
i=0, j=0
i=0, j=1
i=0, j=2
i=1, j=0
Exited nested loops.
3. continue Statement
The continue statement is used to:
• Skip the rest of the code in the current iteration of a loop.
• Immediately proceed to the next iteration of the loop.
Example:
for (int i = 0; i < 5; i++) {
if (i == 3) {
continue; // Skip printing when i equals 3
}
printf("%d ", i);
}
// Output: 0 1 2 4
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
4
next_iteration:;
}
Output:
i=0, j=0
i=0, j=1
i=0, j=2
i=1, j=0
i=1, j=2
i=2, j=0
i=2, j=1
i=2, j=2
Comparison of Statements
Statement Purpose
Skips the remaining part of the loop body for the current iteration
continue
and moves to the next iteration.
Labelled Skips nested iterations using goto (since C lacks direct support for
continue labelled continue).
int main() {
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
5
return 0;
}
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
6
1. Standalone Usage
In standalone usage (not part of another expression), ++a and a++ behave
identically.
int a = 5;
++a; // Pre-increment
printf("%d\n", a); // Output: 6
a++; // Post-increment
printf("%d\n", a); // Output: 7
Here there is no difference in ++a or a++.
2. Usage in Expressions
Case 1: Pre-increment (++a)
• The variable a is incremented first, and the new value is used in the
expression.
int a = 5;
int b = ++a; // Increment first, then assign
printf("a = %d, b = %d\n", a, b); // Output: a = 6, b = 6
Case 2: Post-increment (a++)
• The current value of a is used in the expression first, and then a is
incremented.
int a = 5;
int b = a++; // Assign first, then increment
printf("a = %d, b = %d\n", a, b); // Output: a = 6, b = 5
Another example :
int a = 5, result;
// Using Pre-increment
result = ++a + 10; // Increment a to 6, then add 10
printf("Result = %d, a = %d\n", result, a); // Output: Result = 16, a = 6
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
7
// Using Post-increment
a = 5; // Reset a
result = a++ + 10; // Use a (5) first, then increment to 6
printf("Result = %d, a = %d\n", result, a); // Output: Result = 15, a = 6
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
8
Q9) Differentiate between gets() and scanf() function with help of an example.
Q10) Explain the storage classes in C with the help of example program.
Q11) What are the various dynamic memory allocation functions available in C?
Q12) What is a Pointer? Explain array of pointers to function with help of an
example.
Q13) Differentiate between formatted and unformatted input and output functions.
Q14) Write short note on Structure and Unions.
Q15) Write short note on File Access Modes
Q16) Write short note on Passing Structures to Functions
Q17) What is the use of atoi() function? Explain with an example.
Q18) Compare Array & Strutures. Justify your comparison with help of an example.
Q19) Explain the syntax and usage of inbuilt string functions with suitable example.
Q20) Write a program to find largest and smallest word in a string.
Q21) Explain the following header file math.h, stdlib.h and time.h
Q22) Write a program to check if input word is a palindrome or not.
Q23) Explain switch case statement with help of an example.
Q24) What is Recursive Function? Write a program to find factorial of a number
using Recursion.
Q25) What is Structure? Explain with programming example.
Q26) Write a program to multiply 3 X 3 matrix.
Q27) Explain pointer to pointer and void pointer.
Q28) Explain about conditional compilation directive with its types and suitable
example.
Q29) Explain about fopen(), feof(), fflush() and fclose(0 function.
Q30) What are the data types in C language? Explain with example.
Q31) Differentiate between while and do while statement with example.
Q32) Write any C program using Logical And and Logical Or Operator.
Q33) What do you understand by an array? Explain single dimensional array using
an example.
Q34) Write a Program to input 5 strings and display the same.
Q35) Explain Function Declaration, Function Calling and Function Definition with
example.
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
9
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)
10
Youtube : Anjali Luthra, Instagram : aec_computer_education, Linkedin : Anjali Luthra, Google Play Store: ALCoders
Courses Available for Computer Science related Subjects for School(CBSE, ISC, IB) & College (BCA, B.Tech, B.Sc. CS & IT)