Unit 1 - Practice Quiz

CSE101 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which of the following is a valid C identifier?

Identifiers and keywords Easy
A. 2nd_place
B. _my_variable
C. my-variable
D. int

2 Which data type is most suitable for storing a whole number like 125?

Data types Easy
A. int
B. float
C. char
D. double

3 What is the result of the expression 9 % 4 in C?

Arithmetic operators Easy
A. 2.25
B. 0
C. 2
D. 1

4 Which keyword is used to declare a value that cannot be changed during program execution?

Constants and variables Easy
A. final
B. volatile
C. const
D. static

5 Which operator is used to check if two values are equal?

Relational, Logical, Assignment and conditional operators Easy
A. =
B. :=
C. ==
D. !=

6 Which of the following is a C keyword?

Identifiers and keywords Easy
A. main
B. integer
C. array
D. for

7 Which of the following characters is a valid part of the basic C character set?

The C character set Easy
A. π
B.
C. ¥
D. $

8 What is the purpose of the ++ operator in C?

Unary, Relational, Logical, Assignment and conditional operators Easy
A. To increment a variable's value by 1
B. To add two variables
C. To check for positivity
D. To decrement a variable's value by 1

9 Which data type would you use to store a single letter like 'c'?

Data types Easy
A. bool
B. char
C. int
D. string

10 What is a variable in C programming?

Constants and variables Easy
A. A keyword reserved by the compiler
B. An operator used in expressions
C. A fixed value that does not change
D. A named memory location whose value can be changed

11 Given int x = 10;, which of the following is a valid C expression?

Expressions Easy
A. 10 + x =
B. int y = 5
C. x + 5
D. x ==

12 Which operator performs division in C?

Arithmetic operators Easy
A. \
B. /
C. %
D. div

13 Which operator represents logical OR?

Relational, Logical, Assignment and conditional operators Easy
A. ||
B. &&
C. |
D. !

14 Which operator is used for bitwise AND?

Bitwise operators Easy
A. &
B. AND
C. |
D. &&

15 What does the = operator signify in C?

Unary, Relational, Logical, Assignment and conditional operators Easy
A. Assignment
B. Pointer reference
C. Equality Comparison
D. Logical AND

16 What is the value of the expression 2 + 10 / 5?

Expressions Easy
A. 2.4
B. 4
C. 6
D. 12

17 What is the result of the bitwise OR operation 3 | 5? (Binary of 3 is 011, binary of 5 is 101)

Bitwise operators Easy
A. 7
B. 8
C. 1
D. 15

18 Which of the following cannot be used as a variable name?

Identifiers and keywords Easy
A. while
B. While
C. while_loop
D. _while

19 The conditional operator (?:) is also known as the ____ operator.

Relational, Logical, Assignment and conditional operators Easy
A. Logical
B. Unary
C. Ternary
D. Binary

20 What is the purpose of the sizeof operator?

Data types Easy
A. To set the size of an array
B. To compare the size of two variables
C. To determine the size in bytes of a data type or variable
D. To maximize the value of a variable

21 Which of the following is a valid C identifier but its use is generally discouraged as it may conflict with system-level identifiers or library internals?

Identifiers and keywords Medium
A. 2_variables
B. my-variable
C. auto
D. _my_variable

22 What is the output of the following C code on a typical 64-bit system?

c
#include <stdio.h>

int main() {
printf("%zu", sizeof(3.14));
return 0;
}

Data types Medium
A. 10
B. 8
C. Compiler Error
D. 4

23 What is the value of the variable result after the following C code is executed?

c
int a = -13;
int b = 4;
int result = a % b;

Arithmetic operators Medium
A. 1
B. 3
C. -1
D. -3

24 Given int a = 5, b = 0, c = 10;, what will be the final values of a, b, and c after this expression is evaluated?

int result = (a++ > 5) && (++b < 10) || (c-- > 0);

Unary, Relational, Logical Medium
A. a=6, b=0, c=9
B. a=6, b=1, c=9
C. a=5, b=0, c=10
D. a=6, b=1, c=10

25 What is the value of x after the following operation, and what does this operation typically achieve?

c
unsigned int x = 92; // Binary: 01011100
x = x & (x - 1);

Bitwise operators Medium
A. x will be 46. It performs a right shift by one.
B. x will be 93. It flips the least significant bit.
C. x will be 88. It clears the rightmost set bit.
D. x will be 91. It sets the rightmost unset bit.

26 What will be the value of max after executing the following statement, given a = 10, b = 20, c = 15?

int max = a > b ? a : (b > c ? b : c);

Assignment and conditional operators Medium
A. 20
B. 10
C. Compiler Error
D. 15

27 What is the value of x after the following C expression is evaluated?
int x = 10 + 5 * 2 / 2 - 3 % 2;

Expressions Medium
A. 12
B. 14
C. 6
D. 4

28 What is the behavior of the following C code snippet?

c
const int value = 10;
int ptr = (int)&value;
*ptr = 20;

Constants and variables Medium
A. It will run correctly and value becomes 20.
B. Run-time error (segmentation fault)
C. Compile-time error
D. Undefined Behavior

29 Which C expression can be used to check if an integer n is an even number, without using arithmetic operators like % or /?

Bitwise operators Medium
A. (n << 1) == 0
B. (n ^ 1) == n - 1
C. (n | 1) == n
D. (n & 1) == 0

30 Consider the code float result = 5 / 2;. What value is stored in the result variable?

Data types Medium
A. 2.5
B. 2
C. 2.0
D. Compiler warning, result is unpredictable.

31 What is the output of the following C code?

c
#include <stdio.h>

int main() {
int i = 0;
if (i++ == ++i) {
printf("Equal");
} else {
printf("Not Equal");
}
return 0;
}

Unary, Relational, Logical Medium
A. Not Equal
B. Compiler Error
C. Equal
D. Undefined Behavior

32 What are the final values of a and b after this C statement?

int a = 5, b = 10; a = (b = a + b) - (a = b);

Assignment and conditional operators Medium
A. Undefined Behavior
B. a = 5, b = 15
C. a = 10, b = 5
D. a = -10, b = 15

33 What is the output of the following C code snippet?

c
#include <stdio.h>

int main() {
int result = 5 2 / 3.0 6;
printf("%d", result);
return 0;
}

Arithmetic operators Medium
A. Compiler Error
B. 18
C. 20
D. 0

34 What is the result of the expression (unsigned char) ~0 >> 4 in C?

Bitwise operators Medium
A. 16
B. 15
C. 240
D. 255

35 A C identifier named int_price_in_€; is written in a source file saved with UTF-8 encoding. Why is this code not portable according to the C99 standard?

The C character set Medium
A. The identifier contains a keyword int.
B. The character '€' is not part of the basic source character set.
C. The identifier is too long.
D. Identifiers cannot contain the _ character.

36 What is the value of k after execution?

c
int i = 5, j = 10, k = 15;
k = i, j;

Expressions Medium
A. 5
B. 10
C. Compiler Error
D. 15

37 Given unsigned int x = 0; what is the value of x after the statement x--; is executed?

Data types Medium
A. It will cause a runtime error.
B. -1
C. The maximum value for an unsigned int (UINT_MAX)
D. 0

38 What is the key difference between int * const ptr; and const int * ptr;?

Constants and variables Medium
A. Both declarations are syntactically incorrect.
B. The first is a constant pointer to an integer; the second is a pointer to a constant integer.
C. There is no functional difference between them.
D. The first is a pointer to a constant integer; the second is a constant pointer to an integer.

39 What is the output of this C code snippet?

c
#include <stdio.h>

int main() {
int a = 1, b = 1;
if (a-- && --b) {
printf("A");
} else {
printf("B");
}
printf("%d%d", a, b);
return 0;
}

Unary, Relational, Logical Medium
A. A01
B. A00
C. B10
D. B00

40 What is the value of result after the following C code snippet?

c
int x = 5, y = 10, z = 5;
int result = (x < y) != (y > z);

Relational, Logical Medium
A. true
B. 0
C. 1
D. Compiler Error

41 What is the behavior of the following C code snippet according to the C standard?

c
#include <stdio.h>
int main() {
int i = 5;
int result = i++ * ++i;
printf("%d", result);
return 0;
}

Expressions Hard
A. The behavior is implementation-defined.
B. The code will always print 30.
C. The behavior is undefined.
D. The code will always print 35.

42 Consider the following C code. What will be its output?

c
#include <stdio.h>
int main() {
unsigned int a = 6;
int b = -20;
if (a + b > 5)
printf("Greater");
else
printf("Less or Equal");
return 0;
}

Data types Hard
A. Less or Equal
B. Compiler Error
C. Greater
D. Undefined Behavior

43 What is the output of the following C program? Assume int is a 32-bit two's complement integer.

c
#include <stdio.h>
int main() {
int x = -1;
unsigned int y = (unsigned int)x >> 1;
printf("%d %u", x >> 1, y);
return 0;
}

Bitwise operators Hard
A. -1 2147483647
B. 0 2147483647
C. The output is implementation-defined.
D. -1 0

44 What are the final values of x and y after the following code is executed?

c
int x = 2, y = 0;
int z = y || (x = 0);
y = z || (++x && --y);

Unary, Relational, Logical, Assignment and conditional operators Hard
A. x is 1, y is 1
B. x is 2, y is 1
C. x is 0, y is 1
D. x is 2, y is 0

45 Given the following declarations, which of the subsequent lines of code will cause a compilation error?

c
int x = 10;
int y = 20;
const int * const ptr = &x;

Constants and variables Hard
A. ptr = &y;
B. x = 30;
C. Both *ptr = 30; and ptr = &y;
D. *ptr = 30;

46 What are the values of res1 and res2 after executing this code, according to the C99 standard and later?

c
int a = -13, b = 4;
int res1 = a / b;
int res2 = a % b;

Arithmetic operators Hard
A. The behavior is implementation-defined.
B. res1 is -3, res2 is 3
C. res1 is -4, res2 is 3
D. res1 is -3, res2 is -1

47 Which of the following C expressions correctly evaluates to true if and only if the integer x is a positive power of two?
(A power of two is a number of the form for some non-negative integer , e.g., 1, 2, 4, 8...)

Bitwise operators Hard
A. x && !(x & (x - 1))
B. x > 0 && (x & (x + 1)) == 0
C. x > 0 && (x | (x - 1)) == -1
D. (x ^ (x - 1)) == (2 * x - 1)

48 What is the value of the variable result after the execution of the following code snippet?

c
int a = 0, b = 1, c = -1;
float result = a ? b : c ? b : a;

Assignment and conditional operators Hard
A. 0.0
B. The code has a syntax error.
C. 1.0
D. -1.0

49 What are the final values of size and x after this code executes? Assume sizeof(int) is 4.

c
int x = 10;
size_t size = sizeof(x++);

Unary, Relational, Logical, Assignment and conditional operators Hard
A. size is 4, x is 11
B. size is 5, x is 10
C. size is 4, x is 10
D. size is 5, x is 11

50 What is the output of the following printf statement? Assume sizeof(int) is 4 and sizeof(double) is 8.

c
#include <stdio.h>
int main() {
double d = 3.14;
int i = 5;
printf("%zu", sizeof(i ? d : i));
return 0;
}

Data types Hard
A. 8
B. Compilation Error
C. It depends on the value of i.
D. 4

51 Which of the following C code snippets is guaranteed to cause a compilation error?

Identifiers and keywords Hard
A. c
int main() {
int goto = 5;
return goto;
}
B. c
struct data {
int while;
};
int main() {
struct data d;
d.while = 1;
return 0;
}
C. c
int main() {
goto case;
case:
return 0;
}
D. c
int main() {
typedef int new_type;
auto new_type var = 10;
return 0;
}

52 Assuming a system where int is 32 bits, what is the value of k after the following code is executed?

c
int i = 2147483647; // Maximum signed int (INT_MAX)
int j = 5;
int k = (i + j) / 2;

Expressions Hard
A. -1073741824
B. The behavior is undefined.
C. A runtime exception (integer overflow) occurs.
D. 1073741825

53 What is the decimal value printed by the following C code, assuming an ASCII character set?

c
#include <stdio.h>
int main() {
int val = '\101' - '\x41';
printf("%d", val);
return 0;
}

The C character set Hard
A. 65
B. 0
C. Compilation Error
D. 36

54 What is the final value of the variable a? Note the right-to-left associativity of assignment operators.

c
int a = 3;
a += a -= a *= a;

Assignment and conditional operators Hard
A. The behavior is undefined.
B. 3
C. -15
D. 0

55 What is the value of result after the following snippet executes?

c
int x = -1, y = 2, z = 0;
int result = x < y < z;

Relational, Logical, Assignment and conditional operators Hard
A. 0
B. 1
C. The result is compiler dependent.
D. The expression is invalid.

56 Given an 8-bit system, what are the decimal values of result1 and result2?

c
unsigned char x = 5; // Binary: 00000101
signed char y = -5; // Binary: 11111011 (Two's complement)

unsigned char result1 = ~x + 1;
signed char result2 = ~y + 1;

Bitwise operators Hard
A. result1 is 251, result2 is -5
B. result1 is 5, result2 is 5
C. result1 is -5, result2 is 5
D. result1 is 251, result2 is 5

57 What is the final value of c after the following code snippet is executed?

c
unsigned char c = -1;
c >>= 2;
c = ~c;

Data types Hard
A. -64
B. 191
C. 192
D. 63

58 What is the final value stored in the integer result?

c
int i = 7;
float f = 5.5f;
double d = 2.0;
int result = i * f / d;

Arithmetic operators Hard
A. 19
B. 20
C. 19.25
D. Compilation Error

59 According to the C standard (specifically regarding reserved identifiers), which of the following variable declarations is most likely to cause issues or conflicts, even if it compiles on a particular system?

Identifiers and keywords Hard
A. int RecordCount;
B. int r_count;
C. int record_count;
D. int _record_count;

60 What is the value of k after the execution of this code snippet? Assume int is 16-bit and uses two's complement.

c
int i = 5; // Binary: 0000000000000101
int j = 9; // Binary: 0000000000001001
int k = (i ^ j) + (i & j) * 2;

Bitwise operators Hard
A. 14
B. 16
C. 12
D. 1