Worksheetslevel 2 Quiz 50 MCQs question
Total questions: 50
Worksheet time: 25mins
Which of the following is a correct way to declare an integer variable in C?
int x;
integer x;
num x;
declare int x;
What is the size of int data type in C (on a 32-bit compiler)?
1 byte
2 bytes
4 bytes
8 bytes
Which header file is required to use printf() and scanf()?
stdio.h
conio.h
array.h
studio.h
Which symbol is used to end a statement in C?
:
.
;
,
What will be the output of the following code? int a = 5; printf("%d", a++);
4
5
6
Error
Which operator is used to get the address of a variable?
*
%
&
#
Which of the following is a valid C identifier?
2num
num-1
_num
float
Which loop is guaranteed to execute at least once?
for
while
do-while
if
What is the default return type of a function in C if not specified?
float
char
void
int
Which keyword is used to stop a loop immediately?
exit
stop
break
continue
Which of the following is a logical operator in C?
&
||
=
+
What will be the output of: printf("%d", 10 > 5 && 5 > 2);
0
1
true
false
Which function is used to read a string in C?
gets()
scanf()
fgets()
All of the above
Which of the following correctly declares an array of 10 integers?
int arr;
int arr[10];
array int arr[10];
int arr(10);
Which symbol is used for single-line comments in C?
/* */
//
#
What does the sizeof() operator return?
Value of a variable
Address of a variable
Size in bytes
Data type
Which keyword is used to define a constant in C?
var
constant
define
#define
Which of the following is NOT a data type in C?
int
float
string
char
What is the output of: int x = 3; printf("%d", x * x);
6
9
3
Error
Which statement is used to select among multiple options?
if
switch
for
goto
What does continue do in a loop?
Stops the loop
Skips the current iteration
Restarts the program
Ends the program
Which of the following is used to declare a pointer?
int ptr;
int &ptr;
int *ptr;
pointer int ptr;
What is the output of: printf("%d", 5/2);
2.5
3
2
Error
Which function is used to terminate the program?
stop()
break()
exit()
end()
Which of the following is true about C language?
Case-insensitive
Object-oriented
Platform-dependent
Procedural language
What is the output of the following code? int a = 5; printf("%d %d %d", a++, ++a, a);
5 7 7
5 6 7
Undefined behavior
6 7 7
Which of the following correctly declares a pointer to a constant integer?
int const *p;
int *const p;
const int *const p;
int p const*;
What will be the size of arr? int arr[10][20];
200 bytes
400 bytes
800 bytes
Depends on compiler
What is the output? int x = 10; printf("%d", x == 10 ? 20 : 30);
10
20
30
Error
Which operator has the lowest precedence?
*
+
=
++
What happens if malloc() fails?
Program crashes
Returns 0
Returns NULL
Throws exception
Which is not a valid storage class specifier?
auto
static
register
volatile
What is the output? printf("%d", sizeof('A'));
1
2
4
Depends on compiler
Which function is used to deallocate memory allocated by calloc()?
free()
delete()
remove()
dealloc()
What will be printed? int i = 0; while(i < 3) printf("%d", i++);
012
123
Infinite loop
001122
Which of the following is true about register variables?
Address can be accessed
Stored in RAM only
Faster access than others
Can be global
What is the output? int a = 1; printf("%d", a++ + ++a);
3
4
Undefined behavior
5
Which header file is required for strlen()?
stdio.h
stdlib.h
string.h
math.h
What does sizeof(int*) return?
Size of integer
Size of pointer
Size of array
Compiler dependent only
What is the output? int a = 10; if(a = 5) printf("YES"); else printf("NO");
YES
NO
Error
Undefined
Which loop executes at least once?
for
while
do-while
if
What does continue do?
Terminates loop
Skips current iteration
Stops program
Restarts loop
What is the default return type of a function in C (old standard)?
void
float
int
double
Which of the following cannot be used as an array index?
int
char
float
enum
What is the output? printf("%d", 5/2);
2.5
2
3
Error
What does #define do?
Declares variable
Creates macro
Allocates memory
Defines function
Which is not a logical operator?
&&
||
!
&
What will be the output? char *p = "Hello"; printf("%c", *p);
H
e
Error
Hello
What does fclose() do?
Deletes file
Closes file stream
Clears buffer
Renames file
Which of the following causes dangling pointer?
Using NULL pointer
Using freed memory
Using uninitialized pointer
Using array pointer
