C Programming Questions
C Programming Questions
— 1—
C PROGRAMMING QUESTION BANK
B) -128 to 127
C) -256 to 255
D) 0 to 127
Answer: B
9. Which operator is used to assign a value to a variable?
A) ==
B) =
C) :=
D) =>
Answer: B
[Link] will be the value of x after executing: int x = 5; x += 3;
A) 5
B) 3
C) 8
D) 53
Answer: C
[Link] of the following is a floating-point data type?
A) int
B) char
C) double
D) void
Answer: C
[Link] is the output of sizeof(float)?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) 10 bytes
Answer: B
[Link] many bits are there in 1 byte?
A) 4
B) 6
C) 8
D) 16
Answer: C
[Link] keyword is used to declare a variable that cannot be modified?
A) volatile
B) const
C) final
D) static
Answer: B
[Link] is the correct way to declare a constant in C?
A) constant int x = 10;
B) const int x = 10;
C) final int x = 10;
D) fixed int x = 10;
Answer: B
[Link] variable cannot be modified during program execution?
A) volatile variable
B) static variable
C) const variable
D) automatic variable
Answer: C
[Link] is the scope of a global variable?
A) Only in the function where it is declared
— 2—
C PROGRAMMING QUESTION BANK
— 3—
C PROGRAMMING QUESTION BANK
5-Mark Questions
[Link] the structure of a C program with its main components. Describe the
purpose of each component and how they contribute to the overall functioning
of a program.
[Link] the terms "token" and "identifier" in C. Provide examples of valid and
invalid identifiers, explaining the rules for naming identifiers in C.
[Link] between constants and variables in C. Provide examples of each
and explain how to declare them properly.
[Link] the different data types available in C and their respective ranges.
Explain when and why each data type would be used in a practical program.
[Link] the difference between the keywords "const" and "volatile" in C.
Provide practical scenarios where each would be used.
[Link] a program to declare variables of different data types and display their
sizes using the sizeof operator. Explain the output you receive.
— 4—
C PROGRAMMING QUESTION BANK
10-Mark Questions
[Link] the complete process of compilation and execution of a C program.
Describe each step involved from source code to executable file and the role of
the compiler in this process.
[Link] the concept of variable declaration and initialization in C. Explain the
difference between declaring and initializing a variable, and demonstrate with
examples how improper initialization can lead to errors.
[Link] the memory representation of different data types in C. Describe how
integers, characters, and floating-point numbers are stored in memory, and
explain why the size of data types varies on different systems.
[Link] the importance of following C naming conventions and character sets
in programming. Discuss how proper use of tokens and identifiers improves
code readability and maintainability.
[Link] and contrast the storage classes in C (automatic, static, extern,
register). Explain how each storage class affects variable lifetime and scope,
and demonstrate practical applications of each.
— 5—
C PROGRAMMING QUESTION BANK
— 6—
C PROGRAMMING QUESTION BANK
— 7—
C PROGRAMMING QUESTION BANK
5-Mark Questions
[Link] the difference between if-else and switch statements. Provide
examples of scenarios where each would be more appropriate to use.
[Link] the working of a do-while loop with an example. Explain why it
executes at least once and how it differs from a while loop.
[Link] a program to find the largest among three numbers using nested if
statements. Explain each decision step in the program.
— 8—
C PROGRAMMING QUESTION BANK
10-Mark Questions
[Link] and contrast while, do-while, and for loops in C. Explain the
execution flow of each loop type and provide examples of scenarios where
each would be most appropriate.
[Link] the concept of decision making in C programming. Discuss the
different types of conditional statements available and demonstrate how to
create complex decision-making structures using nested conditions.
[Link] the working of a switch statement with fall-through behavior. Explain
when fall-through is useful and how to prevent unwanted fall-through using
break statements.
[Link] a program to validate user input using appropriate decision-making
constructs. Explain the logic used and how to handle invalid inputs gracefully.
[Link] the concept of jumping statements (break, continue, goto) in C.
Discuss the proper use of these statements and provide examples of their
applications in loops and switch statements.
— 9—
C PROGRAMMING QUESTION BANK
C) 6
D) 10
Answer: B
[Link] do you initialize an array with values in C?
A) int arr[3] = 1, 2, 3;
B) int arr[3] = {1, 2, 3};
C) int arr[] {1, 2, 3};
D) int arr[3] <- 1, 2, 3;
Answer: B
[Link] will be the value of arr[2] for int arr[] = {10, 20, 30, 40};
A) 10
B) 20
C) 30
D) 40
Answer: C
[Link] is a two-dimensional array?
A) An array with two elements
B) An array of arrays
C) An array with two values
D) A matrix with two rows
Answer: B
[Link] do you declare a two-dimensional array in C?
A) int arr[3][4];
B) int arr[3,4];
C) int arr[3:4];
D) int arr(3,4);
Answer: A
[Link] a two-dimensional array int arr[3][4], how many elements are there?
A) 3
B) 4
C) 7
D) 12
Answer: D
[Link] do you access an element in a two-dimensional array?
A) arr[i,j]
B) arr[i][j]
C) arr(i,j)
D) arr{i,j}
Answer: B
[Link] is the address of arr[0] if arr is an array?
A) A random address
B) The base address of the array
C) The address of the first element
D) Both B and C
Answer: D
[Link] you change the size of an array after declaration?
A) Yes, using resize function
B) No, arrays have fixed size
C) Yes, using malloc
D) Yes, using realloc
Answer: B
[Link] happens if you access an array element beyond its size?
A) Error message
B) Program terminates
— 10 —
C PROGRAMMING QUESTION BANK
C) Undefined behavior
D) Returns 0
Answer: C
[Link] do you find the number of elements in an array int arr[10]?
A) length(arr)
B) size(arr)
C) sizeof(arr)/sizeof(arr[0])
D) [Link]()
Answer: C
[Link] is the output of sizeof(arr) for int arr[10]?
A) 10
B) 20
C) 40
D) 50
Answer: C
[Link] strings be stored in a character array?
A) No
B) Yes
C) Only single characters
D) Only using string functions
Answer: B
[Link] do you declare a character array to store a string?
A) char str[20];
B) char str = 20;
C) string str[20];
D) char 20 str;
Answer: A
100. What is a multi-dimensional array?
A) An array with multiple dimensions
B) An array inside another array
C) An array with more than two dimensions
D) All of the above
Answer: D
101. How do you initialize a two-dimensional array?
A) int arr[2][3] = 1,2,3,4,5,6;
B) int arr[2][3] = {{1,2,3},{4,5,6}};
C) int arr[2][3] = {1,2,3,4,5,6};
D) Both B and C
Answer: D
102. What is the first element of array int arr[3][3] = {{1,2,3},{4,5,6},
{7,8,9}};
A) 1
B) 4
C) 7
D) 0
Answer: A
103. In a two-dimensional array, how is data stored in memory?
A) Row-wise
B) Column-wise
C) Random order
D) Depends on the compiler
Answer: A
104. What is the index of the last element in int arr[5]?
A) 5
— 11 —
C PROGRAMMING QUESTION BANK
B) 4
C) 0
D) Undefined
Answer: B
105. Can you have an array of arrays in C?
A) No
B) Yes, it's a multi-dimensional array
C) Only in C++
D) Not recommended
Answer: B
106. What is the output of: int arr[3]; arr[5] = 10;
A) Compilation error
B) Runtime error
C) Undefined behavior
D) Value assigned successfully
Answer: C
107. How many dimensions can an array have in C?
A) Maximum 2
B) Maximum 3
C) No theoretical limit
D) Maximum 10
Answer: C
108. What is an uninitialized array?
A) An array with garbage values
B) An array with all zeros
C) An array with all ones
D) An array with NULL values
Answer: A
109. Can you partially initialize an array in C?
A) No
B) Yes, remaining elements are set to 0
C) Yes, remaining elements are set to garbage
D) Depends on the data type
Answer: B
110. What is the size of char arr[10][20]?
A) 30 bytes
B) 200 bytes
C) 100 bytes
D) Depends on the system
Answer: B
111. In a multi-dimensional array, which index varies the fastest in memory?
A) First index
B) Last index
C) Middle index
D) All vary equally
Answer: B
112. What does arr[i][j] represent in a 2D array?
A) Value at row i, column j
B) Value at column i, row j
C) ith element of jth array
D) Both A and C
Answer: A
— 12 —
C PROGRAMMING QUESTION BANK
5-Mark Questions
113. Explain the concept of one-dimensional arrays in C. Describe how to
declare, initialize, and access array elements. Provide an example program
that demonstrates array usage.
114. Describe the structure and usage of two-dimensional arrays. Explain
how data is stored in memory in row-major order and provide an example of
initializing and accessing elements.
115. Write a program to read 5 numbers into an array, find the sum and
average, and display the results. Explain each step of the program.
116. Explain the concept of multi-dimensional arrays in C. Provide examples
of three-dimensional arrays and explain how memory allocation works for such
arrays.
117. Describe the relationship between arrays and pointers in C. Explain how
array names represent base addresses and how this relationship facilitates
array operations.
118. Write a program to read a matrix of size 3x3 and display it. Explain how
nested loops are used to access each element of the two-dimensional array.
10-Mark Questions
119. Analyze the memory representation and allocation of one-dimensional
and two-dimensional arrays in C. Explain row-major and column-major ordering
and demonstrate how memory addresses are calculated for multi-dimensional
arrays.
120. Design a program to perform matrix operations like addition and
multiplication of two 2D arrays. Explain the logic used in each operation and
demonstrate with examples.
121. Explain the advantages and disadvantages of using arrays in C
programming. Discuss when arrays are appropriate and when dynamic
memory allocation might be better. Provide practical examples.
122. Describe the concept of ragged arrays and how they differ from regular
multi-dimensional arrays. Explain how to implement and use ragged arrays in
C with appropriate examples.
123. Design a comprehensive program that demonstrates the use of both
one-dimensional and two-dimensional arrays. Include operations like
searching, sorting, and transforming array data.
— 13 —
C PROGRAMMING QUESTION BANK
— 14 —
C PROGRAMMING QUESTION BANK
— 15 —
C PROGRAMMING QUESTION BANK
— 16 —
C PROGRAMMING QUESTION BANK
5-Mark Questions
154. Explain the structure of a function in C with all its components. Describe
function declaration, definition, and calling with an example program.
155. Describe the difference between call by value and call by reference in C.
Provide examples of both methods and explain when each is appropriate to
use.
156. Write a program to demonstrate recursion by calculating the factorial of
a number. Explain how the recursive calls and base case work in this example.
157. Explain the concept of storage classes in C. Describe the different
storage classes available and their scope, lifetime, and default values.
158. Describe how arrays are passed to functions in C. Explain why arrays
are always passed by reference and provide an example of a function that
processes an array.
159. Write a program demonstrating the use of strings and string handling
functions. Explain how strings are stored as character arrays and manipulated
in C.
10-Mark Questions
160. Analyze the complete process of function calling and execution in C.
Explain the function call stack, parameter passing mechanisms, and how
return values are handled.
161. Compare and contrast call by value and call by reference in C
programming. Explain the advantages and disadvantages of each method with
practical examples where each is more appropriate.
162. Explain the concept of recursion in detail. Discuss how recursive
functions work, the importance of base cases, and the relationship between
recursion and iteration.
163. Design a program that demonstrates the use of multiple functions
working together. Include examples of different parameter passing methods
and return types.
164. Analyze the storage classes in C programming. Explain how each
storage class affects variable scope, lifetime, and default initialization. Provide
practical examples of when each is used.
— 17 —
C PROGRAMMING QUESTION BANK
UNIT V: Pointers
— 18 —
C PROGRAMMING QUESTION BANK
D) 32 bytes
Answer: B
173. What is a void pointer?
A) A pointer with no data type
B) A pointer that can point to any data type
C) A null pointer
D) Both A and B
Answer: B
174. How do you typecast a void pointer?
A) (int) void_ptr;
B) (int*) void_ptr;
C) void_ptr (int);
D) (int) *void_ptr;
Answer: B
175. What is pointer arithmetic?
A) Mathematical operations on pointers
B) Operations on the values pointed by pointers
C) Incrementing or decrementing pointer addresses
D) All of the above
Answer: C
176. What is the result of ptr++ for a pointer to an integer?
A) Increments by 1 byte
B) Increments by the size of the data type (4 bytes for int)
C) Causes an error
D) Increments by the size of the pointer
Answer: B
177. What is a pointer to a pointer?
A) A pointer that points to another pointer
B) A pointer that points to itself
C) Multiple pointers
D) A reference to a pointer
Answer: A
178. How do you declare a pointer to a pointer?
A) int **ptr;
B) int ptr;
C) int ptr;
D) int *&ptr;
Answer: A
179. What is the relationship between arrays and pointers?
A) Arrays and pointers are the same thing
B) Array names are pointers to the first element
C) Arrays can be used wherever pointers are used
D) Both B and C
Answer: D
180. What is the output of: int arr[5]; printf("%p", arr);
A) Address of the first element
B) Address of the last element
C) Size of the array
D) Number of elements
Answer: A
181. How do you access an array element using pointer notation?
A) *ptr[i]
B) *(ptr + i)
C) ptr[i]
— 19 —
C PROGRAMMING QUESTION BANK
— 20 —
C PROGRAMMING QUESTION BANK
5-Mark Questions
195. Explain the concept of pointers in C with examples. Describe how to
declare, initialize, and use pointers. Demonstrate pointer notation with a
simple program.
196. Describe pointer arithmetic in C. Explain how incrementing and
decrementing pointers works, especially in relation to the data type they point
to.
197. Explain the relationship between arrays and pointers in C. Demonstrate
how array elements can be accessed using pointer notation and array
indexing.
198. Describe dynamic memory allocation in C. Explain the purpose and
usage of malloc and free functions with examples of allocating and
deallocating memory.
199. Write a program to demonstrate the use of pointers with functions.
Include examples of passing pointers as arguments and returning pointers
from functions.
200. Explain the concept of function pointers in C. Demonstrate how function
pointers can be used to call different functions dynamically.
— 21 —
C PROGRAMMING QUESTION BANK
10-Mark Questions
201. Analyze the complete memory model of C programming with emphasis
on pointers. Explain stack memory, heap memory, and how pointers facilitate
access to both. Discuss the relationship between memory addresses and
pointer values.
202. Design a comprehensive program that demonstrates multiple pointer
concepts including pointer arithmetic, pointers to arrays, pointers to functions,
and dynamic memory allocation.
203. Explain the concept of dynamic memory allocation and deallocation in
C. Compare static and dynamic allocation, discuss memory leaks, and provide
strategies to manage heap memory effectively.
204. Describe advanced pointer concepts including pointers to pointers,
function pointers, and pointers in structures. Provide practical examples of
where and why these advanced pointer techniques are used.
205. Analyze the relationship between strings and pointers in C. Explain how
strings are stored, accessed, and manipulated using pointers, and
demonstrate string operations using pointer techniques.
— 22 —