Font size
S
M
L
XL
WorksheetsHitha C Quiz 1 Continue
Total questions: 99
Worksheet time: 3hrs 18mins
Name
Class
Date
1.
A variable declared inside the `main()` function can be accessed directly from another function `my_func()`. Is this true or false?
a)
True
b)
FALSE
c)
Only if `my_func()` is called by `main()`
d)
Only if passed as an argument
2.
Which type of variable has its lifetime restricted to the block in which it is declared?
a)
Global variable
b)
Static variable
c)
Local variable
d)
External variable
3.
If a function `foo()` declares a local variable `x`, and another function `bar()` also declares a local variable `x`, are these two variables the same?
a)
Yes, they refer to the same memory location
b)
No, they are distinct variables in different scopes
c)
Only if `foo()` calls `bar()`
d)
Only if `x` is also a global variable
4.
What happens if you try to access a local variable outside its defined scope?
a)
Compiler error
b)
Runtime error
c)
Undefined behavior
d)
It will be initialized to zero
5.
Where are global variables typically declared in a C program?
a)
Inside a function
b)
Inside the `main()` function only
c)
Outside of any function, usually at the beginning of the source file
d)
In a header file only
6.
What is the default value of a global variable if it is not explicitly initialized?
a)
Garbage value
b)
Zero
c)
Null
d)
Undefined
7.
What is the storage duration of an `auto` variable?
a)
Static storage duration
b)
Dynamic storage duration
c)
Automatic storage duration
d)
Thread local storage duration
8.
Can an `auto` variable be used before its declaration within the same scope?
a)
Yes
b)
No
c)
Only if it's a global variable
d)
Only if it's initialized later
9.
When declaring a global variable that will be used in multiple source files, which keyword should be used in the files where it's *declared* (defined)?
a)
`extern`
b)
`static`
c)
`auto`
d)
No keyword is needed for definition
10.
What happens if you declare an `extern` variable but never define it in any compilation unit?
a)
Compiler error
b)
Linker error
c)
Runtime error
d)
Warning only
11.
Which keyword is often omitted because it's the default for local variables?
a)
`static`
b)
`extern`
c)
`auto`
d)
`register`
12.
The `register` keyword guarantees that a variable will be stored in a CPU register.
a)
True
b)
FALSE
c)
Only for `int` types
d)
Only for `char` types
13.
Why is it generally discouraged to use the `register` keyword extensively?
a)
It makes the code slower.
b)
It can reduce the number of available registers for other optimizations.
c)
It consumes too much memory.
d)
It makes variables global.
14.
Which of the following data types are typically good candidates for `register` variables (if the compiler honors the request)?
a)
Large arrays
b)
Structures
c)
Loop counters
d)
Floating-point numbers
15.
What is the main benefit if a variable *is* successfully placed in a CPU register?
a)
Reduced memory usage
b)
Faster access time
c)
Increased program size
d)
Automatic initialization
16.
A `static` local variable is initialized only once.
a)
True
b)
FALSE
c)
Only if explicitly initialized
d)
Only if it's a `const` variable
17.
What is the scope of a `static` global variable?
a)
Global scope
b)
File scope
c)
Local scope
d)
Block scope
18.
Consider a function `void counter() { static int count = 0; count++; printf("%d\n", count); }`. What will be the output if `counter()` is called three times consecutively?
a)
1, 1, 1
b)
0, 1, 2
c)
1, 2, 3
d)
Undefined behavior
19.
Can a `static` local variable be accessed by another function in the same file without passing it as an argument?
a)
Yes, always
b)
No
c)
Only if declared `extern static`
d)
Only if it's a pointer
20.
Which of the following is evaluated at compile time and substituted directly into the code?
a)
`const int x = 5;`
b)
`#define PI 3.14159`
c)
`enum { MAX = 100 };`
d)
`static const int Y = 20;`
21.
What is the type of a constant defined using `#define`?
a)
`int`
b)
`char`
c)
It has no specific type
d)
`float`
22.
To define a constant that is local to a specific function and cannot be changed, which keyword combination would you use?
a)
`static const`
b)
`extern const`
c)
`auto const`
d)
`register const`
23.
What is the primary reason to use constants in C programming?
a)
To make variables mutable
b)
To improve program readability and maintainability
c)
To increase execution speed
d)
To reduce memory usage
24.
If you define `const float PI = 3.14;`, what is the best practice if `PI` needs to be used in another source file?
a)
Redefine it with `#define` in the other file.
b)
Declare it as `extern const float PI;` in the other file's header.
c)
Pass it as an argument to every function.
d)
It cannot be used in another file.
25.
Which of the following is NOT a type of operator in C?
a)
Arithmetic
b)
Logical
c)
Typing
d)
Relational
26.
Operators that work on two operands are called:
a)
Unary operators
b)
Binary operators
c)
Ternary operators
d)
N-ary operators
27.
In the expression `a + b * c`, which operation is performed first due to operator precedence?
a)
Addition
b)
Multiplication
c)
It depends on `a` and `b`
d)
It's undefined behavior
28.
What is the purpose of parentheses `()` in an expression?
a)
To define a function
b)
To force a specific order of evaluation
c)
To declare a variable
d)
To indicate a comment
29.
Which of the following is a ternary operator in C?
a)
`++`
b)
`?:`
c)
`==`
d)
`!`
30.
The order in which operations are performed if they have the same precedence is determined by their:
a)
Associativity
b)
Operand count
c)
Type
d)
Keyword
31.
Which operator calculates the remainder of a division?
a)
`/`
b)
`*`
c)
`%`
d)
`+`
32.
What is the result of `7 / 2` when both operands are integers?
a)
3.5
b)
3
c)
4
d)
Undefined
33.
What will be the value of `result` after `double result = 15 / 4;`?
a)
3
b)
3.75
c)
4
d)
Undefined
34.
If `x = 10` and `y = 3`, what is `x % y`?
a)
0
b)
1
c)
3
d)
10
35.
Which of the following will correctly calculate the square of an integer `num`?
a)
`num ^ 2`
b)
`num ** 2`
c)
`num * num`
d)
`pow(num, 2)` (requires `<math.h>`)
36.
If `int i = 5;` what is the value of `i` after `i++;`?
a)
5
b)
6
c)
4
d)
Undefined
37.
If `int j = 10;` what is the value of `k` and `j` after `int k = ++j;`?
a)
k = 10, j = 11
b)
k = 11, j = 10
c)
k = 11, j = 11
d)
k = 10, j = 10
38.
Which of the following is equivalent to `x = x - 1;`?
a)
`--x;`
b)
`x--;`
c)
Both A and B
d)
None of the above
39.
Using increment/decrement operators inside complex expressions can lead to:
a)
Clearer code
b)
Improved performance
c)
Undefined behavior if not careful about order of evaluation
d)
Fewer bugs
40.
What is the value of `a` after `int a = 0; a = a++ + ++a;`?
a)
1
b)
2
c)
3
d)
Undefined behavior
41.
Which operator checks if two operands are *not* equal?
a)
`==`
b)
`=`
c)
`!=`
d)
`<`
42.
In C, a true condition is represented by:
a)
The keyword `true`
b)
Any non-zero value
c)
The keyword `false`
d)
Only the value `1`
43.
What is the result of the expression `(7 >= 7)`?
a)
`true`
b)
`false`
c)
`1`
d)
`0`
44.
Which of the following evaluates to false in C?
a)
`10 > 5`
b)
`0`
c)
`3 != 3`
d)
`'A' == 65` (ASCII)
45.
If `a = 10` and `b = 20`, what is the result of `(a < b)`?
a)
`0`
b)
`1`
c)
`true`
d)
`false`
46.
Which logical operator performs a short-circuit evaluation, stopping if the first operand is false?
a)
`||`
b)
`&&`
c)
`!`
d)
`&`
47.
What is the output of `printf("%d", (1 && 0));`?
a)
`1`
b)
`0`
c)
`true`
d)
`false`
48.
If `x = 5`, what is the result of `(x > 10 || x < 0)`?
a)
`1`
b)
`0`
c)
`true`
d)
`false`
49.
What does the logical NOT operator (`!`) do?
a)
Performs bitwise inversion
b)
Changes the sign of a number
c)
Inverts the truth value of a boolean expression
d)
Concatenates strings
50.
What is the result of `(!0)`?
a)
`0`
b)
`1`
c)
Undefined
d)
Error
51.
Which of the following correctly represents "A is true AND B is false"?
a)
`A && !B`
b)
`!A && B`
c)
`A || !B`
d)
`!A || B`
52.
If `a = 6 (0110)` and `b = 3 (0011)`, what is `a & b`?
a)
7 (0111)
b)
2 (0010)
c)
4 (0100)
d)
1 (0001)
53.
Which operator is used to set a specific bit to 1?
a)
Bitwise AND (`&`)
b)
Bitwise OR (`|`)
c)
Bitwise XOR (`^`)
d)
Bitwise NOT (`~`)
54.
If `x = 5 (0101)`, what is `x ^ 3 (0011)`?
a)
6 (0110)
b)
7 (0111)
c)
4 (0100)
d)
1 (0001)
55.
The bitwise left shift operator (`<<`) is equivalent to:
a)
Division by powers of 2
b)
Multiplication by powers of 2
c)
Modulo operation
d)
Addition of powers of 2
56.
What is the result of `8 >> 3`?
a)
1
b)
2
c)
4
57.
Which operator flips all the bits of its operand?
a)
`!`
b)
`~`
c)
`^`
d)
`&`
58.
If `flags = 0b00001010` (decimal 10), and you want to clear the 2nd bit (0-indexed) while leaving others unchanged, what operation would you use?
a)
`flags = flags | (1 << 2);`
b)
flags = flags & ~(1 << 2);
c)
`flags = flags ^ (1 << 2);`
d)
`flags = flags << 2;`
59.
Which bitwise operator can be used to check if a specific bit is set (is 1)?
a)
Bitwise OR (`|`)
b)
Bitwise XOR (`^`)
c)
Bitwise AND (`&`)
d)
Bitwise NOT (`~`)
60.
What is the typical use for bitwise operators in embedded systems?
a)
String formatting
b)
Complex calculations
c)
Controlling hardware registers and flags
d)
User input validation
61.
If `int a = 5; a *= 3;`, what is the new value of `a`?
a)
5
b)
8
c)
15
d)
2
62.
What is the equivalent of `x %= 5;`?
a)
`x = x + 5;`
b)
`x = x - 5;`
c)
`x = x % 5;`
d)
`x = x / 5;`
63.
After `int value = 20; value >>= 2;`, what is `value`?
a)
5
b)
10
c)
40
d)
80
64.
Which operator is used for bitwise OR and assignment?
a)
`|=`
b)
`&=`
c)
`^=`
d)
`!=`
65.
If `char c = 'A'; c ^= 32;`, what is the new value of `c` (assuming ASCII)?
a)
`'A'`
b)
`'a'`
c)
`'C'`
d)
Undefined
66.
When performing an assignment operation, the right-hand side (RHS) of the assignment operator is always evaluated:
a)
After the left-hand side (LHS)
b)
Before the left-hand side (LHS)
c)
Simultaneously with the LHS
d)
It depends on the data type
67.
Which of the following is typically defined using the `const` keyword?
a)
An array that changes its size during execution
b)
A loop counter that varies
c)
A mathematical constant like `e` (Euler's number)
d)
A string that needs to be modified by the user
68.
Can a pointer to a `const` integer be used to modify the integer it points to?
a)
Yes, always
b)
No, it's read-only through that pointer
c)
Only if cast to a non-const pointer
d)
Only if the integer itself is not `const`
69.
If you define a constant `BUFFER_SIZE` using `#define`, where does the substitution take place?
a)
During linking
b)
During compilation
c)
During preprocessing
d)
During runtime
70.
What is the main difference in how the compiler treats `const int x = 10;` versus `#define X 10`?
a)
`const` allows `x` to be modified, `#define` doesn't.
b)
`const` creates a variable in memory with a type, `#define` is text substitution.
c)
`#define` is faster to access.
d)
`const` is limited to integers.
71.
If a global variable `int count = 0;` exists, and a function `void func() { int count = 5; }` is called, what is the value of the global `count` after `func()` executes?
a)
0
b)
5
c)
Undefined
d)
Compiler error
72.
What is the storage class of a `static` variable?
a)
Automatic
b)
Dynamic
c)
Static
d)
Register
73.
If `register int i;` is declared, and the compiler ignores the `register` hint, where will `i` be stored?
a)
In a special `register` memory area
b)
In main memory (like an `auto` variable)
c)
It will cause a compiler error
d)
It will be optimized out entirely
74.
What is the result of `10.0 / 4`?
a)
2
b)
2.5
c)
3
d)
Undefined
75.
Which of the following expressions is *not* equivalent to `x >= y`?
a)
`!(x < y)`
b)
`x > y || x == y`
c)
`y <= x`
d)
`!(x > y)`
76.
If you need to check if a number `num` is within the range [10, 20] (inclusive), which logical expression is correct?
a)
`num > 10 && num < 20`
b)
`num >= 10 || num <= 20`
c)
`num >= 10 && num <= 20`
d)
`num > 10 || num < 20`
77.
What is the purpose of using bitmasks with bitwise operators?
a)
To encrypt data
b)
To perform network communication
c)
To selectively manipulate specific bits or groups of bits
d)
To generate random numbers
78.
If `unsigned int x = 1;` what is `x << 31` on a 32-bit system?
a)
0
b)
`INT_MIN`
c)
`INT_MAX`
d)
Undefined behavior
79.
Which of the following is equivalent to `x = x / 2;` for positive integers, using a bitwise operator?
a)
`x << 1;`
b)
`x >> 1;`
c)
`x ^ 1;`
d)
`x & 1;`
80.
If you have a variable `status` and you want to toggle (flip) the 5th bit (0-indexed) while leaving other bits unchanged, which bitwise operation would you use?
a)
`status = status & (1 << 5);`
b)
`status = status | (1 << 5);`
c)
`status = status ^ (1 << 5);`
d)
`status = status >> 5;`
81.
What is the result of `int a = 7; a |= 2;`? (7 = 0111, 2 = 0010)
a)
5
b)
7
c)
3
d)
10
82.
Which of the following assignment operators has the lowest precedence?
a)
`*=`
b)
`+=`
c)
`=`
d)
`<<=`
83.
After `int val = 12; val &= 5;`, what is `val`? (12 = 1100, 5 = 0101)
a)
4
b)
1
c)
12
d)
5
84.
When is memory allocated for a local variable?
a)
At compile time
b)
At runtime, when the function/block is entered
c)
At runtime, when the program starts
d)
When the variable is first accessed
85.
What happens to the value of a local variable when its function exits?
a)
It retains its value for the next call.
b)
It is automatically reset to zero.
c)
Its memory is deallocated and its value becomes undefined (garbage).
d)
It becomes a global variable.
86.
What is the default initial value of an `auto` variable if not explicitly initialized?
a)
Zero
b)
Garbage value
c)
Null
d)
One
87.
What is the main advantage of using a `static` variable inside a function over a global variable for persistent state?
a)
It makes the variable faster.
b)
It restricts the variable's visibility to only that function, avoiding naming conflicts and unintended modification from other parts of the program.
c)
It allows the variable to be modified by other files.
d)
It allocates memory on the heap.
88.
Which of the following is considered a compile-time constant?
a)
`#define SIZE 100`
b)
`const int MAX = 200;`
c)
Both A and B (in many contexts)
d)
Neither A nor B
89.
What is the result of `sizeof(int)`?
a)
The number of bytes an integer occupies on the system
b)
The number of bits an integer occupies
c)
The maximum value an integer can hold
d)
The number of integer variables declared
90.
Which operator has right-to-left associativity?
a)
`+`
b)
`*`
c)
`=`
d)
`%`
91.
If `int x = 5; int y = 5; int a = x++; int b = ++y;`, what are the final values of `a`, `b`, `x`, and `y`?
a)
a=5, b=6, x=6, y=6
b)
a=6, b=5, x=6, y=6
c)
a=5, b=5, x=6, y=6
d)
a=6, b=6, x=5, y=5
92.
Which of the following is equivalent to `!(A && B)`?
a)
`!A || !B`
b)
`!A && !B`
c)
`A || B`
d)
`A && B`
93.
If `condition1` is true and `condition2` is false, what is the result of `(condition1 || condition2)`?
a)
True
b)
False
c)
Undefined
d)
Error
94.
What is the purpose of the bitwise `~` operator?
a)
Logical NOT
b)
Sign inversion
c)
One's complement
d)
Two's complement
95.
When is it generally bad practice to chain multiple assignment operators like `a = b = c = 10;`?
a)
Never, it's always good.
b)
When `b` or `c` are functions with side effects.
c)
When variables are different data types.
d)
Only when using floating point numbers.
96.
What happens to the memory occupied by global variables when the program finishes execution?
a)
It is explicitly freed by the programmer.
b)
It is automatically reclaimed by the operating system.
c)
It remains allocated for other programs.
d)
It becomes corrupted.
97.
Can `extern` be used with a local variable?
a)
Yes, always.
b)
No, `extern` is only for global declarations.
c)
Only if the local variable is `static`.
d)
Only if the local variable is `const`.
98.
What is the purpose of `static` when applied to a function?
a)
It makes the function recursive.
b)
It restricts the function's visibility to the current file.
c)
It makes the function a member of a structure.
d)
It makes the function asynchronous.
99.
Which is a good use case for an `enum` to define constants?
a)
For mathematical constants like PI
b)
For defining a set of related integer constants (e.g., days of the week, error codes)
c)
For string literals
d)
For binary values only
Reset
