What is Variable?

A named container that holds a value in a program. It is declared with a type such as integer or real and changed by assignment. Assigning a new value discards the previous one.

Japanese name: 変数

Variable appears in 70 practice questions across 11 topics, including Programming Basics (Pseudocode Tracing), Linkers, Loaders & Executables, Multicore & Synchronization.

Field: Programming Basics (Pseudocode Tracing)

Try it: questions about Variable

When debugging a program compiled with optimization, some variables may show as "unavailable." What is the main reason?

  1. AWith optimization enabled, debuggers cannot load the program at all
  2. BVariable values change randomly with every compilation
  3. CRegister reuse or removed computations left no value
Show answer and explanation

Answer: C. Register reuse or removed computations left no value

Optimization keeps variables in registers rather than memory and reuses those registers once a value is no longer needed, and constant propagation may remove computations entirely. So when the debugger stops, a variable's value may no longer exist anywhere, and it is shown as "optimized out" or similar. When debugging, it is common to reduce optimization or use a debug-oriented optimization level. Debuggers can still load optimized programs.

In C, a global variable written outside any function as "int limit = 100;" is generally placed in which section?

  1. A.data (initialized data)
  2. B.bss (uninitialized data)
  3. C.text (machine code)
Show answer and explanation

Answer: A. .data (initialized data)

Global and static variables with a non-zero initial value go in the .data section, and their initial values are stored in the file. When the program is loaded, this content is copied into memory as is, so limit is already 100 when main starts. Because .data is modified at run time, it is mapped readable and writable.

Variable in the explanations

Questions that mention Variable (70)

  1. When debugging a program compiled with optimization, some variables may show as "unavailable." What is the main reason?
  2. In C, a global variable written outside any function as "int limit = 100;" is generally placed in which section?
  3. Of the global variables above, which are generally placed in the .bss section?
  4. Where is a non-static local (automatic) variable declared inside a C function placed at run time?
  5. In C, what is true of the starting values of a local variable and a global variable declared without initializers?
  6. Two cores each hold a copy of variable x in their own caches. After core 0 writes x, what problem could occur when core 1 reads x if there were no cache coherence mechanism?
  7. The code above doubles the shared variable counter using CAS(&p, expected, new). When does the CAS fail so the loop repeats?
  8. In C, why is marking a flag variable shared between threads volatile not sufficient for synchronization?
  9. On an 8-bit microcontroller, a timer interrupt increments the 32-bit variable ticks, and the main code reads ticks to compute elapsed time. Why is a wildly wrong value occasionally read?
  10. The following program passes values along three variables. What are the values of a, b and c after it runs?
  11. In the following nested loop, the inner loop starts from the outer variable i. What is the value of c after it runs?
  12. ÷ is division; when the result is assigned to an integer variable (including a function argument), the fractional part is discarded. What does the following function f return when called as f(9087)?
  13. ÷ is division; when the result is assigned to an integer variable (including a function argument), the fractional part is discarded. What does the following function toBin return when called as toBin(12)?
  14. ÷ is division; when the result is assigned to an integer variable (including a function argument), the fractional part is discarded. When the following function pow is called as pow(2, 10), how many times is pow called, including the first call?
  15. ÷ is division; when the result is assigned to an integer variable (including a function argument), the fractional part is discarded. The following program finds in lo the index of the first value that is at least x in the integer array data, which is sorted in ascending order (indices start at 1). x is no greater than the last element of data. What should replace 【a】 in the program?

Books on Programming Basics (Pseudocode Tracing) Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Stack Argument Array Pointer Modulo operation Recursion Linker volatile (type qualifier) Microcontroller (MCU) Heap memory

Back to the glossary