TomoLink
TCS NQT GuideTCS NQT Programming Logic & CS FundamentalsScope of Variables, Registers, and Storage Classes

Scope of Variables, Registers, and Storage Classes

Learn core concepts, essential formulas, and attempt practice questions designed on the latest TCS NQT testing patterns.

Key Concepts & Formulas

  • 1Storage Classes in C: auto, register, static, extern.
  • 2static variables: Retain their value across function call cycles.
  • 3register variables: Hint compiler to store in CPU registers for fast access.

TCS NQT Style Practice Questions

Practice Question 1

What is output of: void func() { static int c=0; c++; printf("%d ", c); } called twice?

A) 1 2
B) 1 1
C) 0 1
D) 0 0

Correct Answer: A) 1 2

Step-by-step Solution: Static variable c is initialized once. 1st call increments c to 1. 2nd call retains 1, increments to 2. Output is '1 2'.

Practice Question 2

Where are register variables stored?

A) CPU Registers
B) RAM
C) Stack
D) Heap

Correct Answer: A) CPU Registers

Step-by-step Solution: register class requests the compiler to place the variable directly in high-speed CPU registers.

Study Pro-Tip

Static variables are initialized only once, before the main program executes.