Font size
WorksheetsC Programming Multiple Choice Questions
Total questions: 40
Worksheet time: 40mins
Which operator is used to access the address of a variable?
*
&
#
@
What is the output?
int a = 10, b = 5, c;
c = a > b ? a : b;
printf("%d", c);
10
5
0
1
What is the output of the following code? #include <stdio.h>
int main() {
int a[] = {1, 2, 3, 4, 5};
int *p = a;
printf("%d", *(p + 2));
return 0;
}
1
2
3
Garbage Value
Which of the following is a valid main function declaration?
void main()
int main()
main()
All of the above
What is the output?
#include <stdio.h>
void main() {
static int i;
printf("%d", i);
}
Garbage value
0
1
Error
Which function is used to read a string from the standard input?
gets()
scanf()
getchar()
Both a and b
What is the role of the stdlib.h header file?
Standard Input/Output
String operations
Memory allocation functions like malloc()
Mathematical functions
What is the output of printf("%d", 5 + 3 * 2);?
16
11
10
13
Identify the problem with this code related to memory management.
Memory leak
Dangling pointer
Nothing, it's correct.
malloc is used incorrectly.
Which of the following is a logical AND operator?
&
&&
|
||
What is the output? int x = 5;
printf("%d %d %d", x, ++x, x++);
5 6 6
7 7 5
5 6 5
The output is compiler-dependent.
What is the keyword used to define a constant value in C?
constant
#define
const
#Define
What is the output if the user enters "5"?
int num;
if (scanf("%d", &num))
printf("Valid");
else
printf("Invalid");
Valid
Invalid
Error
Undefined
What is the value of a local variable that is not initialized?
0
1
A garbage value
NULL
What is the output of printf("%d", 10 / 3);?
3.33
3
4
3.0
What is the output?
char str[] = "Hello";
printf("%d", sizeof(str));
5
6
7
Garbage value
What is the size of the int data type in a typical 32-bit C compiler?
1 byte
2 bytes
4 bytes
8 bytes
What does the strcmp(str1, str2) function return if str1 and str2 are equal?
1
0
-1
The length of the string
What is the output?
int i = 2;
int j = i++ + ++i;
printf("%d", j);
4
5
6
Undefined / Compiler-dependent
Which loop is guaranteed to execute at least once?
for loop
while loop
do-while loop
None of the above
What is the value of x after the execution?
int x = 10;
int *ptr = &x;
*ptr = 20;
10
20
Address of x
Garbage value
What is the correct extension for a C source file?
.c
.cpp
.java
.py
What does the continue statement is used to:
Exit from the main function
Exit from the current loop iteration
Jump to a label
Restart the program
What is the output of printf("%c", 'A' + 1);?
A
B
66
Error
25. What Does this code demonstrate
#include <stdio.h>
int main() {
int x = 10;
{
int x = 20;
printf("%d ", x);
}
printf("%d", x);
return 0;
}
Global variable
Scope of a variable
Lifetime of a variable
Both b and c
Which of the following correctly declares a pointer to a function that takes an integer and returns a float?
float *f(int);
float (*f)(int);
float (*f)(int*);
float f(int *);
What is the output?
#include <stdio.h>
int main() {
int i = 0;
for(; i; i--)
printf("Hello ");
return 0;
}
Prints "Hello" infinitely
Prints "Hello" once
Does not print anything
Error
A function in C can return:
Only one value
Multiple values
No value
Both a and c
What will the following code print?
#include <stdio.h>
void fun(int *x) {
x = x + 10;
}
int main() {
int a = 5;
fun(&a);
printf("%d", a);
return 0;
}
5
10
15
Error
Which header file is needed to use the printf() and scanf() functions?
<conio.h>
<stdlib.h>
<stdio.h>
<math.h>
What does the break statement do inside a loop?
Skips the current iteration
Exits the loop immediately
Restarts the loop
Pauses the program
What is a structure in C?
A collection of same data types
A collection of different data types
A special type of function
A type of pointer
C is a _____ language.
High-Level
Low-Level
Assembly
Machine
The printf function is used for:
Taking input
Displaying output
Allocating memory
File operations
Which of the following is the correct way to declare a string?
char str[20] = {'C', 'L', 'A', 'N', 'G'};
char str[] = "CLANG";
char *str = "CLANG";
All of the above
An array index in C always starts from:
0
1
-1
Can be defined by the user
What does the following code do? int *p; int a = 10; p = &a;
Declares p as an integer
Makes p point to the address of a
Makes p hold the value of a
Declares a new variable
The switch statement is used with:
Integer expressions
Character expressions
Floating-point expressions
Both a and b
In a 1D array int arr[5];, what does arr represent?
The first element
The base address of the array
The last element
The size of the array
Which format specifier is used for a float value?
%d
%f
%c
%lf
