Monday, April 16, 2012
Extern storage class in C!!!
External storage class is used to give the reference for the global variable which is visible to the whole application/program. When you declare variable as extern, variable can't be initialised, its only a declaration. Memory will not be allocated to the extern variable. But it will point to the variable which is already declared somewhere in other file. Extern is the default for all global variables and functions.
Sample code for Extern storage class:
Output :
i is 10
When you have multiple files, and you declared a global variable in on file and you want to use the same varaibel in other file, you need to declare the variable as extern in other file. Just for understanding and letting to know the developer, we are using extern. By default global variables are extern, if you not declare as extern, compiler by default assumes all global variable are extern variables.
- Keyword: extern
- Default value: zero if not initialised .
- Memory Location: Main memory
- Scope: Global to the whole program/application
- Lifetime: Global to the whole program/application
Sample code for Extern storage class:
// file name is file1.c and code is below static int i=10; // i is static, so its scope is limited to this file only main() { print(); } // file name is file2.c and code is below #includeextern int i; // i is extern, so i value is somewhere in ohter file extern void print(); void print() { printf("i is %d\n",i); // will get error here, because in file1.c i is static }
Output :
i is 10
When you have multiple files, and you declared a global variable in on file and you want to use the same varaibel in other file, you need to declare the variable as extern in other file. Just for understanding and letting to know the developer, we are using extern. By default global variables are extern, if you not declare as extern, compiler by default assumes all global variable are extern variables.
Subscribe to:
Post Comments (Atom)
Popular Posts
-
A universally unique identifier ( UUID ) is an identifier standard used in software construction, standardized by the Open...
-
Recently I started working on Japser Studio professional for my new project Cloud to generate the reports. I was very new to all cloud ...
-
Below is C program for AVL Tree implementation. #include<stdio.h> #include<malloc.h> typedef struct bst { int info; int hei...
-
strcmp is another string library function which is used to compare two strings and returns zero if both strings are same , returns +ve valu...
-
One of the complex operation on binary search tree is deleting a node. Insertion is easy by calling recursive insertion. But deletion wont...
-
We have recently faced one tricky issue in AWS cloud while loading S3 file into Redshift using python. It took almost whole day to inde...
-
Object slicing: when a derived class object is assigned to a base class object. only base class data will be copied from derived class and...
-
We have faced lot of weird issues while loading S3 bucke t files into redshift. I will try to explain all issues what we faced. Before go...
-
Below code is to find the cube root of a given integer number with out using pow math library function. Its very simple and brute force...
-
Recently we faced one issue in reading messages from SQS in AWS cloud where we are processing same message multiple times. This issue we...
No comments:
Post a Comment