Wednesday, April 6, 2016

'Extern' Storage Class Specifier

You can use extern keyword along with function declaration as well, but that's a redundant operation since functions have external linkage by default. ie; They can be accessed globally from other places.

'Typedef' Qualifier

'typedef' is not a storage class specifier, but it allows us to give an alias (new name) to existing data types (built-in or user defined datatypes). Sytax of 'typedef' is as given below,
typedef data_type alias; 
Let's consider the following example
typedef int number;
Here, we've given an alias to data type 'int' which is 'number'. So now we can use 'number' as a type in variable declaration and definition to hold an integer values. By creating an alias, we can use it as given below
number first, second;
It means 'first' and 'second' are of the 'number' data type which in turn is an integer. So, 'first' and 'second' are also integers.

Summary of Storage Class Specifiers

Table given below summarizes the storage location, initial default value, scope and life time of different storage class specifiers
Storage ClassSpace Allocated inDefault Initial ValueScopeLife
autoMemoryGarbageLocal ScopeAlive within the declared code block
registerCPU RegisterGarbageLocal ScopeAlive within the declared code block
staticMemory0Local ScopeValue retained between invocations
externMemory0Global ScopeAlive till program exit

No comments: