LearnFrenzy
Sign in Take a free test

C Variables · Exercise 1 of 4

C Variables Variables MCQ

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twelve multiple-choice questions on naming, initialisation, scope, lifetime, linkage and the storage classes – including thread_local and C23 auto. Pick an option to check your answer instantly.

Question 1 Easy

What is the value of int count; declared inside a function, before it is assigned?

A 0
B 1
C Indeterminate (garbage) – reading it is a bug
D -1
Question page & discussion
Question 2 Easy

What is the value of int total; declared outside all functions, before it is assigned?

A Garbage
B 0
C 1
D It does not compile
Question page & discussion
Question 3 Easy

Which of these is not a valid identifier?

A _count
B count_2
C 2count
D Count
Question page & discussion
Question 4 Medium

What does extern int x; at file scope do?

A Defines x and sets it to 0
B Declares x, which must be defined somewhere else in the program
C Creates a local copy of x
D Makes x constant
Question page & discussion
Question 5 Easy

How long does a static variable declared inside a function exist?

A Until the function returns
B For the whole run of the program
C Until the next call
D Only during the first call
Question page & discussion
Question 6 Medium

What is the effect of static on a variable defined at file scope?

A It keeps its value between function calls
B It gives the variable internal linkage: other source files cannot access it
C It makes it read-only
D It moves it to the stack
Question page & discussion
Question 7 Easy

Where can a variable declared inside { … } be used?

A Anywhere in the function
B From its declaration to the end of that block
C Anywhere in the file
D Only on the next line
Question page & discussion
Question 8 Medium

Which is true about register int i;?

A It is guaranteed to be stored in a CPU register
B Its address cannot be taken with &
C It is visible in other files
D It starts at 0
Question page & discussion
Question 9 Medium

Which statement correctly distinguishes scope from lifetime?

A They are the same thing
B Scope is where the name is visible; lifetime is when the storage exists
C Scope is for globals, lifetime for locals
D Lifetime is measured in lines of code
Question page & discussion
Question 10 Hard

Which variable name should a program avoid because it is reserved for the implementation?

A my_count
B count_
C _Count
D countUpper
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links