Languages [3i Infotech Placement]: Sample Questions 147 - 147 of 546

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

Question 147

Edit

Describe in Detail

Essay▾

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

Explanation

  • 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: