Worksheets" C Proficiency "
Total questions: 50
Worksheet time: 38mins
Guess the output of the following code:
2.500000
2.000000
2
Compilation Error
How many times will the loop execute?
4
5
6
Infinite times
What is the correct way to declare an integer pointer is
int ptr;
int *ptr;
ptr *int;
int &ptr;
Find the value of x in this code:
10
15
20
40
Output of the following code is:
10
20
30
40
This function returns ---------
Fibonacci sequence
Factorial of n
Sum of first n numbers
Power of n
Output of the following code is:
True
False
Error
Undefined behaviour
What will be the output?
3.14
3.140000
3.1
Error
Guess the output of the following code:
1
2
3
0
Output of the code will be:
H
e
l
Error
Which of the following is a potential issue with using gets()?
It's slow.
It can cause a buffer overflow
It can only read strings of a fixed length.
It's deprecated but still safe to use if you're careful.
What is the purpose of a function pointer?
To store the return value of a function.
To pass a function as an argument to another function.
To create a new function dynamically.
To call a function from a different file.
Output of the below code is:
5 6
6 6
5 7
6 7
Purpose of typedef keyword is---------
To define a constant.
To create an alias for an existing data type.
To declare a function.
To include a header file.
What is the output of the following code:
Hello
Jello
H
Error
What is the output of the following code
5
10
15
Error
What is the difference between const int p and int const p?
They are the same
const int p makes the pointer constant, int const p makes the integer constant
const int p makes the integer constant, int const p makes the pointer constant.
const int *p is invalid syntax.
This code will print -----
o
\0
Error
0
What is a dangling pointer?
A pointer that points to a valid memory location.
A pointer that points to a memory location that has been freed.
A pointer that has not been initialized.
A pointer that points to a constant value.
Identify the correct statement for a switch in C:
Multiple cases can have identical constant expressions
The default statement is optional
switch expressions accept floating-point types
The break is mandatory after every case
Identify the wrong statement:
A for loop can have multiple initialization expressions
The while condition is evaluated before each iteration
A loop variable must be declared globally
Infinite loops are possible in all types of loops
Which of the following causes an infinite loop?
for (i = 0; i < 10; i++)
while (1);
do { } while (i > 10);
for (i = 0; i < 5; i--);
What will be the result of the following code?
Compile-time error
1 2 3 4 5
Infinite Empty loop
1
Which statement is valid for the switch construct?
break is required for the default block
Cases must be in ascending order
All cases must end with a semicolon
case values must be constant
Output of the following code snippet is:
0 0 0
0 1 0
1 1 1
No output
What is the output of the code below?
x is 10
x is not 10
Error
Nothing
Find the output of the below code:
x and y are equal
x and y are not equal
Unpredictable
No output
Which of the following statements about the given line of code is true?
int p = (int)100;
It is illegal in C
p points to memory location 100, but dereferencing is undefined behavior.
It is always safe to dereference p.
p is an integer variable initialized to 100.
Guess the output:
Equal
Not Equal
Equal Not Equal
Compiler Error
What will be the result of the following expression in C?
int a = 5, b = 10, c = 15;
a = b++ + --c * a;
a = 5, b = 11, c = 14
a = 15, b = 11, c = 14
a = 5, b = 11, c = 14
a = 20, b = 11, c = 14
Find the output:
1 2
1 2 3
1 2 3 4
Infinite Loop
What does strlen("C\0Program") return?
9
1
8
10
Given int arr[3][3], which of the following is an incorrect way to access an element?
arr[1][2]
*(arr[1]+2)
((arr+1)+2)
arr[3][3]
Which of the following is used to compare string contents in C?
==
strcmp()
=
equals()
After calling free(ptr), what value does ptr hold?
NULL
Garbage value
The original address (dangling pointer)
Zero
Which of the following is not a valid printf format specifier?
%zu
%lld
%p
%n
---------------- keyword is used to declare a function that cannot be modified in other source files.
static
volatile
const
extern
What does the following code print?
10
20
Compile-time Error
Run-time Error
Which of the following function declarations is valid in C?
a) int func(int a, float b = 3.14);
b) int func(int, float);
int func(void int);
void func(void) int;
What is the output of this code snippet?
yes
no
5
6
Fill in the missing condition to ensure a loop runs exactly 5 times:
i <= 5
i != 5
i < 5
i >= 5
What is the missing statement to declare a pointer to a function that takes two integers and returns a float?
float *func(int, int);
float (*func)(int, int);
float (func)(int, int);
float (*func())(int, int);
What is the missing access specifier for bit-fields in this struct?
char
unsigned int
float
int
Fill in the missing statement to copy a string in C:
strcat
strncpy
strcpy
strcmp
Which control statement is missing to stop infinite execution in the following loop?
break
continue
return
goto
To round off x (float), to an int value, the correct way to do is
y = (int)(x + 0.5)
y = int(x + 0.5)
y = (int)x + 0.5
y = (int)((int)x + 0.5)
What will be the output of the following C code?
128
-128
a) Compiler-dependent
None of these
Pointer arithmetic is not possible on ___.
Integer pointers
Float pointers
Character pointers
Void pointers
Find the output:
20
24
4
18
Find the output:
10
11
12
13
