Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 94 - 94 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 94

C & C Plus Plus

Describe in Detail


Describe the storage allocation and scope of global, extern, static, local and register variables?


  • Storage allocation concerns with the memory that is, where the storage space is allocated for variables and functions.
  • Scope of a variable is implicitly determined by its storage allocation.
  • Storage allocation is specified by the keywords auto, extern, static and register.
  • ‘auto’ variables
    • Store in the memory storage.
    • Majority of the variables in a program.
    • Their scope might be local or global.
  • ‘extern’ variables
    • Global variables and can be declared in another source file which could be external
    • They are obviously allocated on the heap accessible across function calls etc.
  • ‘register’ variables
    • Allocated in the CPU registers.
    • Storage and accessibility is faster than other variables as they are stored in CPU itself.
    • Use for variables with repeated usage or critical access time.
  • ‘static’ variables
    • Survive lifetime of the program and unlike global variables provide limited scope.
    • These variables are automatically initialized to zero and could be specified as ‘auto’ and ‘extern’ variables.
    • The values are retained, even though they are declared in local scope, between the repeated function calls to the same function.

Developed by: