Skip to content

C variable quiz

Which of the following are valid Python code? (Select all that apply)

In C, what is a "variable"?


Which of the following is a valid C variable name?


What is the primary purpose of the const keyword when declaring a variable?


Which option correctly declares a character variable grade and initializes it to 'A'?


A variable declared inside a function, like main, is called a...


What does the sizeof operator in C return?


In C, what is the data type of the result of the expression 10 + 5.5?


What is the main characteristic of a variable declared with the unsigned keyword (e.g., unsigned int)?


What is the initial value of a non-static local variable if you don't explicitly initialize it?


In C, are the variable names totalAmount and totalamount considered the same?


What is the defining characteristic of a local variable declared with the static keyword inside a function?


What is the primary use of the extern keyword with a variable declaration?


In the C assignment statement x = 100;, the variable x represents...


What is the key difference between a variable declaration and a variable definition?


Consider this code:

int count = 10; // Global variable

void my_func() {
    int count = 5; // Local variable
    printf("%d", count);
}
What will be printed when my_func() is called?

An unsigned char can hold values from 0 to 255. What is the value of x after this code runs? unsigned char x = 255; x++;


What is the primary advantage of using double over float?


How do you correctly declare a variable p_age that is a pointer to an integer?


The volatile keyword tells the compiler that a variable's value...


What is the fundamental difference between 'A' and "A" in C?


Which of the following is an invalid C variable name?


What is the result of the statement int a, b; a = b = 20;?


In C99 and later, what is the standard way to declare a boolean variable is_complete?


What is the register storage class specifier intended to do?


What is the primary purpose of the char data type in C?


Which statement correctly declares a floating-point variable price and initializes it to 19.99?


Error processing MCQ: not enough values to unpack (expected 3, got 2)
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.14.5/x64/lib/python3.14/site-packages/mkdocs_mcq/plugin.py", line 21, in format_mcq
    _, frontmatter, content = source.split("---", 2)
    ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 3, got 2)

  • [ ] 16
  • [ ] 15.75
  • [ ] The code will fail to compile.
  • [x] 15

    Correct! Explicitly casting a double to an int truncates the value, discarding the fractional part. It does not round.

---

```mcq
---
type: single
question: A variable declared outside of all functions at the top of a source file is known as a...
----
- [x] Global variable.
  > Correct! It has file scope and is accessible to all functions within that file.
- [ ] Local variable.
- [ ] Private variable.
- [ ] Universal variable.

Error processing MCQ: not enough values to unpack (expected 3, got 2)
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.14.5/x64/lib/python3.14/site-packages/mkdocs_mcq/plugin.py", line 21, in format_mcq
    _, frontmatter, content = source.split("---", 2)
    ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 3, got 2)

File_B.c:

extern int global_counter;

Which statements are true? (Select all that apply)

  • [x] File_A.c contains a definition of global_counter.

    Correct. Memory is allocated and an initial value is provided, so this is a definition.

  • [x] File_B.c contains a declaration of global_counter.

    Correct. The extern keyword tells the compiler that global_counter exists and is defined elsewhere. No memory is allocated here.

  • [ ] File_B.c also defines the variable global_counter.

    Incorrect. The extern keyword explicitly makes this a declaration, not a definition.

  • [ ] This code will cause a linker error because the variable is declared twice.

    Incorrect. This is the standard, correct way to share a global variable across files. A linker error would occur if both files contained a definition.