Unit 2: Principles of programming - Practice Quiz
1 Which function is the mandatory entry point of every C program where execution begins?
begin()
printf()
start()
main()
2
Which section of a C program is used to include header files like #include <stdio.h>?
3 Which of the following is NOT part of the C character set?
@
5
4 Which of the following is a valid identifier in C?
total_marks
float
2ndvalue
my var
5 How many keywords are defined in standard (ANSI) C?
6 Which keyword is used to declare a constant whose value cannot be changed during program execution?
final
fixed
const
static
7 What is a variable in C?
8 Which data type is used to store a single character in C?
double
char
float
int
9 Which of the following is used to store numbers with a decimal point?
int
char
void
float
10
Which format specifier is used to print an integer using printf()?
%s
%f
%c
%d
11 Which function is used to read a single character from the keyboard?
puts()
putchar()
getchar()
printf()
12 Which function is used to display a string on the screen and automatically moves the cursor to a new line?
getchar()
gets()
scanf()
puts()
13
In scanf("%d", &n);, what does the & symbol represent?
n
n
14
What is the result of the expression 5 + 3 * 2 in C?
15 Which arithmetic operator returns the remainder of a division?
/
%
*
-
16
What does the ++ operator do in C?
17 Which operator is used to check whether two values are equal in C?
!=
>=
==
=
18 Which of the following is the logical AND operator in C?
&&
!
||
&
19
What is the value of x after int x = (5 > 3) ? 10 : 20;?
20 Which of the following is the bitwise OR operator in C?
^
&
|
||
21
In a standard C program, which section is used to include header files and define macros before the main() function?
22 Which of the following is NOT part of the valid C character set?
0 to 9
@ used as an operator
# and %
23 Which of the following is a valid C identifier?
my-var
2ndValue
_total_2
float
24 How many keywords are reserved in standard ANSI C (C89/C90)?
25
What is the output of the following code?
c
const int x = 10;
x = 20;
printf("%d", x);
10
0
20
26
On a typical 32-bit system, what is the size (in bytes) of a double variable?
27
What is the output of the following code?
c
char c = 'A';
printf("%d", c);
65
0
97
A
28 Which function reads a full line of text including spaces until a newline is encountered?
scanf("%s", str)
getchar()
putchar()
gets()
29
What does printf("%d", printf("AB")); output?
AB2
AB1
2AB
AB0
30
In scanf, why is the & operator used before variable names for basic types like int?
31
What is the value of the expression 5 + 3 * 2 - 8 / 4?
12
4
6
9
32
What is the output of the following code?
c
printf("%d", 17 % 5);
3
2
0
3.4
33
What is the output of the following code?
c
int a = 5;
int b = a++ + ++a;
printf("%d", b);
11
10
12
13
34
What is the value of the expression (10 > 5) > 3 in C?
0
1
3
35
In the expression a && b, if a evaluates to 0, what happens to b?
b is always evaluated first
b is evaluated and result is 1
b is not evaluated due to short-circuiting
36
What is the value of max after this code runs?
c
int a = 8, b = 12;
int max = (a > b) ? a : b;
8
12
1
0
37
After executing int x = 10; x += x -= 5;, what is the value of x?
5
0
15
10
38
What is the result of 12 & 10 in C?
14
2
8
6
39
What is the value of 5 << 2?
20
7
10
25
40
What is the output of the following code?
c
printf("%d", (int)(7.0 / 2));
4
2
3
3.5
41
Assuming 32-bit int, what is the value of the expression ~5 & 0xFF when printed with %d?
42
In C, what is the result of -7 % 3 and 7 % -3 respectively (C99 and later)?
1 and 1
2 and -2
-1 and 1
-1 and -1
43
Given int i = 5;, what value is assigned in int j = i++ + ++i; and what is i afterward? (Common compiler behavior)
j = 10, i = 6
j is unspecified due to undefined behavior; result is not guaranteed
j = 11, i = 7
j = 12, i = 7
44
What does printf("%d\n", (int)(3.99 + 2.99)); print, and why?
5
6
6.98
7
45
For int a = 0, b = 5; int r = a++ && ++b;, what are the final values of r, a, and b?
r = 0, a = 1, b = 6
r = 1, a = 1, b = 6
r = 0, a = 1, b = 5
r = 0, a = 0, b = 5
46
Given input 12 34 (with a space), what does this code print?
c
int a, b;
scanf("%d%d", &a, &b);
printf("%d", a + b);
1234
12
46
47
What is the value of x after int x = 4; x = (x > 2) ? (x < 8 ? x * 2 : x / 2) : x + 1;?
4
2
8
5
48
On a system with 8-bit char, what does unsigned char c = 300; printf("%d", c); print?
-44
44
255
300
49
What is the output of printf("%d", 1 << 3 | 1 << 1);?
10
6
8
16
50
What does the following print on a typical system?
c
unsigned int u = 10;
int i = -1;
if (i < u) printf("less"); else printf("not less");
not less
less
51 Which of the following is a valid C identifier?
double
_count2
2count
my-var
52
What is the value of the expression 5 + 3 * 2 % 4 - 1?
6
3
0
8
53
What is the output of printf("%d", 010 + 0x10);?
24
26
20
110
54
What does printf("%d", printf("abc")); output?
3abc
abc3
abc
abc0
55
What does printf("%d", 3 < 2 < 1); print?
1
0
56
Which expression correctly toggles (flips) the 3rd bit (bit index 2, value 4) of an integer n while leaving other bits unchanged?
n & ~(1 << 2)
n & (1 << 2)
n ^ (1 << 2)
n | (1 << 2)
57
What is printed by float f = 0.1f; printf("%d", f == 0.1);? (Assume IEEE-754)
1
0
58
Given int a = 10; int b = -a++;, what are the values of b and a afterward?
b = -11, a = 11
b = -11, a = 10
b = -10, a = 10
b = -10, a = 11
59
What is the output of int x = 5; printf("%d %d", x != 0, !x);?
0 1
1 5
1 0
5 0
60
On a system where int is 4 bytes, what does printf("%d", sizeof('A')); most likely print in a C program (not C++)?
1
4
2
8
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →