WorksheetsProgramming Lab Quiz
Total questions: 25
Worksheet time: 22mins
What is the correct syntax to declare a variable in C?
int x;
integer x;
var x;
x int;
What will be the output of the following code?
int x = 5;
printf("%d", x++);
6
5
Error
Undefined
Which of the following is the correct way to call a function in C?
call myFunction();
myFunction();
function myFunction();
def myFunction();
What is the size of int in C (on a 32-bit machine)?
8 bytes
4 bytes
2 bytes
1 bytes
What is the output of the following code?
int a = 10;
printf("%d", ++a);
10
11
12
Error
Which of the following is not a valid data type in C?
float
real
int
char
Which operator is used for "address of" in C?
*
&
%
#
What is the correct syntax for a function using call by reference?
void fun(int x)
void fun(int *x)
void fun(ref int x)
void fun(int &x)
What will the following code print?
int a = 2;
int b = a++ + ++a;
printf("%d", b);
5
6
7
8
What does the following code output?
int x = 10;
printf("%d", *&x);
10
Address of x
Error
Garbage value
Which of the following is true about main() function in C?
It is optional.
Execution starts from main().
It can be called from other functions only.
It is a library function.
What does the following code return?
int x = 10;
printf("%d", x == 10);
10
1
0
Error
What will be the output?
int a = 5;
printf("%d", a += 2);
5
7
2
Error
Which is used to comment a single line in C?
/* comment */
// comment
<!-- comment -->
# comment
Which is used to comment a multiple line in C?
/* comment */
// comment
<!-- comment -->
# comment
What is the correct way to return a value from a function?
return;
return x;
exit(x);
return x, y;
What is the output of the following code?
int x = 2;
switch (x) {
case 1:
printf("One ");
case 2:
printf("Two ");
case 3:
printf("Three ");
default:
printf("Default");
}
Two
Two Three Default
One Two Three Default
Error
What will be the output of the following code?
int a = 5;
switch (a % 2) {
case 0:
printf("Even");
break;
case 1:
printf("Odd");
break;
default:
printf("Default");
}
Even
Odd
Default
Error
What will be the output of the following code?
char grade = 'B';
switch (grade) {
case 'A':
printf("Excellent");
break;
case 'B':
printf("Good");
break;
case 'C':
printf("Average");
break;
default:
printf("Poor");
}
Excellent
Good
Average
Poor
Which format specifier is used for float in printf()?
%c
%d
%f
%s
Which of these will correctly swap two variables using call by reference?
void swap(int a, int b) {
int temp = *a;
a = b;
*b = temp;
}
Correct
Incorrect
Will give error
Will not swap
What will be the output?
#include <stdio.h>
int main() {
int a = 5, b = 10;
int c = a++ + ++b;
printf("%d %d %d", a, b, c);
return 0;
}
5 10 15
6 11 16
6 11 15
5 11 15
Output of this recursive function?
#include <stdio.h>
void print(int n) {
if(n > 0) {
print(n - 1);
printf("%d ", n);
}
}
int main() {
print(3);
return 0;
}
3 2 1
1 2 3
2 3 1
1 3 2
What is the output of this pointer manipulation?
#include <stdio.h>
int main() {
int a = 10, b = 20;
int p = &a, q = &b;
p = q;
printf("%d %d", a, b);
return 0;
}
10 10
20 20
20 10
erroe
What will this print?
char ch = 'A';
printf("%d", ch);
A
65
'A'
Error
