0% found this document useful (0 votes)
4 views

Question Bank Theory C Programming

The document provides a compilation of important questions and previous year questions related to C programming, covering topics such as preprocessor directives, control flow statements, arrays, recursion, and file operations. It includes explanations and examples for various concepts like the use of #define, break and continue statements, and the differences between local and global variables. Additionally, it lists numerous programming tasks and concepts that are essential for understanding and mastering C programming.

Uploaded by

nawal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Question Bank Theory C Programming

The document provides a compilation of important questions and previous year questions related to C programming, covering topics such as preprocessor directives, control flow statements, arrays, recursion, and file operations. It includes explanations and examples for various concepts like the use of #define, break and continue statements, and the differences between local and global variables. Additionally, it lists numerous programming tasks and concepts that are essential for understanding and mastering C programming.

Uploaded by

nawal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1

AEC (Anjali Engineering Classes)


Most Important Questions &
PYQs – C Programming

Q1) What is the use of #define preprocessor?


Ans. The #define preprocessor directive in C is used for defining macros, which are
symbolic constants or functions that are substituted directly into the code during the
preprocessing phase (before compilation). It is a powerful feature of the
preprocessor that helps improve code readability, maintainability, and efficiency.
Uses of #define
1. Defining Constants
o You can use #define to create symbolic names for constants instead of
using magic numbers, making the code easier to read and update.
#define PI 3.14159
#define MAX_LENGTH 100
double area = PI * radius * radius;
2. Defining Macros (Inline Functions)
• #define can be used to define small, inline functions to save overhead
from function calls.
#define SQUARE(x) ((x) * (x))

int result = SQUARE(5); // Expands to (5 * 5)

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

• Exit a switch statement after a case is executed.


Example:
for (int i = 0; i < 5; i++) {
if (i == 3) {
break;
}
printf("%d ", i);
}
Output: 0 1 2
In a switch statement:
int num = 2;
switch (num) {
case 1: printf("One"); break;
case 2: printf("Two"); break;
default: printf("Default");
}
Output: Two
2. Labelled break Statement
C does not directly support labelled break. However, similar functionality can be
achieved using the goto statement to exit nested loops.
Example:
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == 1 && j == 1) {
goto end; // Simulates labelled break
}
printf("i=%d, j=%d\n", i, j);
}
}
end:
printf("Exited nested loops.\n");

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

4. Labelled continue Statement


C does not directly support labelled continue. However, you can use the goto
statement to simulate skipping the remainder of nested loops.
Example:
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == 1 && j == 1) {
goto next_iteration; // Simulates labelled continue
}
printf("i=%d, j=%d\n", i, j);
}
continue;

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

break Exits the nearest enclosing loop or switch statement immediately.

Exits nested loops or blocks by using goto (since C lacks direct


Labelled break
support for labelled break).

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

Q3) Write example code to declare two dimensional array.


Q4) Differentiate between Local & Global Variable in C.
Q5) What is the difference between ++a and a++?
Q6) Explain various types of operators available in C++.
Q7) What is Recursion? Explain with the help of a program in C.
Q8) Explain various looping statements in C with the help of suitable example.
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?

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

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.
Q36) Explain array within structure using example.
Q37) Explain Array of structures using an example.
Q38) Explain Nested Structure.

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

Q39) What is enumerated data type?


Q40) Explain pointer to function with suitable example.
Q41) Write a program to show read and write operation on a file in C.
Q42) Explain fseek and ftell .
Q43) What are preprocessor directives?
Q44) Write short note on getch(), getche(), putchar, getchar().
Q45) What do you understand by multidimensional array? Write a program to search
an element in an array.
Q46) What is call by Value and Call by reference in C Programming ?
Q47) Write short note on typedef statement.
Q48) What is Pointer Arithmetic?
Q49) Write a Program in C to print Fibonacci Series.
Q50) Write a program in C to print all prime numbers from 1 to 100.
Q51) Write a C Program to sort an array elements.
Q52) Write a program in c to demonstrate Command line arguments.
Q53) Write a program in C to find sum of numbers from 1 to n
Q54) What is prototyping? Explain with example.
Q55) What is the difference between scanf and getchar statement
Q56) Write a program in C to add two n X m matrices.
Q57) What is sizeof operator?
Q58) What is a pointer? Describe the application of pointers in a C program
Q59) What is a dynamic array? Show with an example how to create a dynamic
array in C.
Q60) Write a program in C language to copy content of one file to another file.
Q61) What is a file? How does append mode differ from write mode?
Q62) Describe the following functions: fseek(), ftell() and rewind()
Q63) Explain different types of keywords and identifiers in C.
Q64) Write a C program to check if a number is palindrome or not.
Q65) Write a C program to find greatest of three numbers.
Q66) Write a program to print following :
*******

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

*****
***
*
Q67) Write a program to read 4 digit number and find average of those digits.
Q68) What is the use of goto statement? Explain with program.
Q69) What is a Macro? Explain parameterized and non parameterized macros.
Q70) Explain about fprintf and fscanf function.
Q71) What is type casting? Explain various types of type casting.
Q72) Explain basic structure of C Program.
Q73) Write a peogram in C to concatenate two strings.
Q74) What is an expression? Explain the precedence of operators and associativity.
Q75) Explain formatted console i/o function. Also write various format specifiers used
with these function.

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)

You might also like