
Q31
Q31 Identify the error in this C code:
int main() {
int i = 0;
while(i < 3) {
i++;
}
printf("%d ", i);
return 0;
}
Infinite loop
Syntax error
No error
Prints nothing
Q32
Q32 What is the primary purpose of a function in C?
Code reuse and modularity
Error handling
Memory management
User interface creation
Q33
Q33 What is recursion in C?
A function calling another function
A function that has no return type
A function calling itself
A loop within a function
Q34
Q34 Pseudocode:
FUNCTION Add(a, b) RETURN a PLUS b END FUNCTION CALL Add(5, 10)
15
5
10
Error
Q35
Q35 Spot the mistake:
int main() {
int result = sum(5, 10);
printf("%d", result);
return 0;
}
int sum(int a, int b) {
return;
}
Missing return value in sum
Syntax error
No error
Incorrect function parameters
Q36
Q36 How do you declare an array of integers in C?
int arr[10];
array int[10];
int array 10;
[10]int array;
Q37
Q37 What happens when you try to access an array element outside its bounds in C?
Syntax error
Compilation error
Runtime error
Undefined behavior
Q38
Q38 What is the size of a 2-dimensional array int arr[3][4]; in C?
3
4
12
Cannot be determined
Q39
Q39 What is the default value of an uninitialized array in C?
0
1
Random memory value
-1
Q40
Q40 In C, can an array be resized after its declaration?
Yes
No
Only if it's a dynamic array
Only in C99 standard
Q41
Q41 What will be the output of the following C code?
int main() {
int arr[] = {1, 2, 3, 4, 5};
printf("%d", arr[3]);
return 0;
}
1
2
3
4
Q42
Q42 What is the output of this C code?
int main() {
int arr[5] = {1, 2, 3};
printf("%d", arr[4]);
return 0;
}
0
3
Random value
Error
Q43
Q43 What does the following C code do?
int main() {
int arr[3][4] = {{1, 2}, {3, 4}};
printf("%d", arr[1][1]);
return 0;
}
Prints 2
Prints 3
Prints 4
Prints 0
Q44
Q44 Pseudocode:
ARRAY numbers[5] SET numbers[0] TO 1 PRINT numbers[0]
Prints 1
Prints 0
Prints random value
Syntax error
Q45
Q45 Pseudocode:
FUNCTION SumArray(ARRAY arr, SIZE) SET sum TO 0 FOR i FROM 0 TO SIZE-1 INCREMENT sum BY arr[i] RETURN sum
Calculates the sum of array elements
Returns the size of the array
Returns the first element
Syntax error
Q46
Q46 Identify the error in this C code:
int main() {
int arr[3];
arr[3] = 10;
printf("%d", arr[3]);
return 0;
}
Array index out of bounds
Syntax error
No error
Wrong printf format
Q47
Q47 What is a pointer in C?
A variable that stores a memory address
A function
An array
A data type
Q48
Q48 How do you access the value pointed to by a pointer in C?
Using the * operator
Using the & operator
Directly by the pointer name
Using the -> operator
Q49
Q49 How does dynamic memory allocation differ between malloc and calloc?
malloc initializes memory to zero, calloc does not
calloc initializes memory to zero, malloc does not
They don't differ
malloc allocates more efficiently
Q50
Q50 What will be the output of the following C code?
int main() {
int a = 10;
int *p = &a;
printf("%d", *p);
return 0;
}
10
Address of a
Error
0
Q51
Q51 Complete the C code:
int main() {
int a = 10;
int *p = &a; ___;
printf("%d", a);
return 0;
}
to make the output 20.
*p = 20;
p = 20;
a = 20;
&a = 20;
Q52
Q52 Pseudocode:
FUNCTION Increment(VALUE POINTER p) INCREMENT VALUE AT p END FUNCTION CALL Increment(ADDRESS OF num)
Increments num
Prints num
Returns num's address
Error
Q53
Q53 Spot the mistake:
int main() {
int a = 10, *p = &a;
*p++;
printf("%d", a);
return 0;
}
Incrementing a instead of *p
Syntax error
No error
Incorrect use of increment operator
Q54
Q54 How is a string represented in C?
As a series of characters followed by a null character
As an array of integers
As a single character
As a special data type
Q55
Q55 What is the purpose of the strcpy function in C?
To compare two strings
To concatenate two strings
To copy one string to another
To find the length of a string
Q56
Q56 What does the strcat function do in C?
Concatenates two strings
Compares two strings
Converts a string to an integer
Splits a string into tokens
Q57
Q57 What is the return value of strcmp when the two strings are equal in C?
0
1
-1
The length of the strings
Q58
Q58 What happens if a string copied using strcpy is larger than the destination array?
Syntax error
Compilation error
Runtime error
Undefined behavior
Q59
Q59 What is the purpose of the strchr function in C?
Finds the first occurrence of a character in a string
Concatenates two strings
Reverses a string
Compares two strings
Q60
Q60 Complete the C code:
int main() {
char str[20];
___;
printf("%s", str);
return 0;
}
to copy "Hello" into str.
strcpy(str, "Hello");
str = "Hello";
strncpy(str, "Hello", 5);
strcat(str, "Hello");


