Compare Automatic, Register, Static and External Variables in C

Let us understand the difference between various storage classes in C programming language. Below is the table that will show difference between Automatic, Register, Static and External Variables storage Classes in C.

Feature Automatic Variable Register Variable Static Variable External Variable
1 Keyword Used auto register static extern
2 Storage Memory CPU registers Memory Memory
3 Default initial value Garbage Value Garbage Value Zero Value Zero Value
4 Scope Local to the block in which the variable is defined Local to the block in which the variable is defined Local to the block in which the variable is defined Global
5 Life Till the control remains within the block in which the variable is defined Till the control remains within the block in which the variable is defined Value of the variable persists between different function calls As long as the program’s execution doesn’t come to an end
6 Use General purpose use. Most widely used compared to other storage classes Used extensively for loop counters Used extensively for recursive functions Used in case of variables which are being used by almost all the functions in a program

You may also like...

2 Responses

  1. Keerthimanu gattu says:

    Very neatly given !

  1. July 2, 2014

    […] Also see: Comparison of Automatic, Register, Static and External Variables in C […]

Leave a Reply

Your email address will not be published. Required fields are marked *

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet