c programming storage class
TRANSCRIPT
-
7/27/2019 C Programming Storage Class
1/2
Home C Programming C++ Programming FollowFollow
C Programming
C Introduction
C Keywords and Identifier
C Variables and Constants
C Programming Data Types
C Programming input/Output
C Programming Operators
C Precedence and Associativity
C Introduction Examples
C Decisions And Loops
C Programming if...else
C Programming for Loops
C do...while Loops
C break and continue
C Programming switch...case
C Programming goto
C Decision & Loop Examples
C Programming Functions
C Functions Introduction
C User-defined Functions
C Function Types
C Programming recursion
C Storage Class
C Function Examples
C Programming Arrays
C Arrays Introduction
C Multi-dimensional Arrays
C Arrays & Functions
C Arrays Examples
C Programming Pointers
C Pointers Introduction
C Pointers And Arrays
C Pointers And Functions
C Dynamic Memory Allocation
C Pointer Examples
C Programming Strings
C Programming Strings
C String Functions
C String Examples
C Structure And Unions
C Structure Introduction
C Structures and Pointers
C Structure and Function
C Programming Unions
C Structure Examples
C Programming Files
C Files Input/OutputC Files Examples
More On C Programming
C Programming Enumeration
C Programming Preprocessors
C Library Functions
C Programming Examples
Follow Us
C Programming Storage Class
Every variable and function in C programming has two properties: type and storage class. Type refers to the data
type of variable whether it is character or integer or floating-point value etc.
There are 4 types of storage class:
1. automatic
2. external
3. static
4. register
Automatic storage class
Keyword for automatic variableauto
Variables declared inside the funct ion body are automatic by default. The se variable are also known as local variables
as they are local to the function and doesn't have meaning outside that function
Since, variable inside a function is automatic by default, keyword auto are rarely used.
External storage classExternal variable can be accessed by any function. They are also known as global variables. Variables declared outside
every function are external variables.
In case of large program, containing more than one file, if the global variable is declared in file 1 and that variable is
used in file 2 then, compiler will show error. To solve this problem, keyword extern is used in file 2 to indicate that,
the variable specified is global variable and declared in another file.
Example to demonstrate working of external variable
#include
voidCheck();
int a=5;
/* a is global variable because it is outside every function */
int main(){
a+=4;
Check();
return 0;
}
voidCheck(){
++a;
/* ----- Variable a is not declared in this function but, works in any
function as they are global variable ------- */
printf("a=%d\n",a);
}
Output
a=10
Register Storage Class
Keyword to declare register variableregister
Example of register variable
register int a;
Register variables are similar to automatic variable and exists inside that particular function only.
Search
Like 804
Python devs at SlideShare
www.slideshare.net
Love python? Work with SlideShare at New Delhi. Apply Now!
http://www.programiz.com/c-programming/library-functionhttp://www.programiz.com/c-programming/c-file-exampleshttp://www.programiz.com/c-programming/c-structure-exampleshttp://www.programiz.com/c-programming/c-structure-functionhttp://www.programiz.com/c-programming/c-structureshttp://www.programiz.com/c-programming/string-handling-functionshttp://www.programiz.com/c-programming/c-dynamic-memory-allocationhttp://www.programiz.com/c-programming/c-pointers-arrayshttp://www.programiz.com/c-programming/c-pointershttp://www.programiz.com/c-programming/c-arrays-exampleshttp://www.programiz.com/c-programming/c-arrays-functionshttp://www.programiz.com/c-programming/c-arrayshttp://www.programiz.com/c-programming/c-recursionhttp://www.programiz.com/c-programming/c-user-defined-functionshttp://www.programiz.com/c-programming/c-decision-making-loops-exampleshttp://www.programiz.com/c-programming/c-switch-case-statementhttp://www.programiz.com/c-programming/c-break-continue-statementhttp://www.programiz.com/c-programming/c-for-loophttp://www.programiz.com/c-programming/precedence-associativity-operatorshttp://www.programiz.com/c-programming/c-input-outputhttp://www.programiz.com/c-programming/c-variables-constantshttp://www.programiz.com/c-programming/c-keywords-identifierhttp://www.programiz.com/http://www.programiz.com/c-programminghttp://www.programiz.com/cpp-programminghttp://www.programiz.com/http://www.programiz.com/http://googleads.g.doubleclick.net/aclk?sa=l&ai=CtcnsYUzuUYmxGYjOigfe-4D4BLns5ZUC2e_epSDAjbcBEAEg_4rkIVD48qOg_v____8BYOXK5YO0DqAB18G47wPIAQGoAwHIA9MEqgSQAU_Qh_tamywdQGkNwGTzd-p579quKAaKmB7URA4vBbSSNowmyAPqkiEAu6Kc19v81qaYEP1y6MKjVfCyU_9UUngwCtz1SlNgn3V046qTBrhENPMOvUYR09vg60QcWi-H2ABaXa2Kz8mlPnBJjaE2E7q43uB0MEBvG4u7MiS6xsYi4clKQSzksUFkrfKSZQEoeYAHkb7HEA&num=1&sig=AOD64_3waxyz_TRX1NMyIpx09jSJyJz-MA&client=ca-pub-9007421361448641&adurl=http://www.slideshare.net/about/workatslideshare&nm=3https://twitter.com/intent/follow?original_referer=http%3A%2F%2Fwww.programiz.com%2Fc-programming%2Fc-storage-class®ion=follow_link&screen_name=programiz&tw_p=followbutton&variant=2.0http://www.google.com/url?ct=abg&q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://www.programiz.com/c-programming/c-storage-class%26gl%3DIN%26hl%3Den%26client%3Dca-pub-9007421361448641%26ai0%3DCtcnsYUzuUYmxGYjOigfe-4D4BLns5ZUC2e_epSDAjbcBEAEg_4rkIVD48qOg_v____8BYOXK5YO0DqAB18G47wPIAQGoAwHIA9MEqgSQAU_Qh_tamywdQGkNwGTzd-p579quKAaKmB7URA4vBbSSNowmyAPqkiEAu6Kc19v81qaYEP1y6MKjVfCyU_9UUngwCtz1SlNgn3V046qTBrhENPMOvUYR09vg60QcWi-H2ABaXa2Kz8mlPnBJjaE2E7q43uB0MEBvG4u7MiS6xsYi4clKQSzksUFkrfKSZQEoeYAHkb7HEA&usg=AFQjCNF6jpWgo_ws9rZt31ATBcQh_Km45ghttp://googleads.g.doubleclick.net/aclk?sa=l&ai=CtcnsYUzuUYmxGYjOigfe-4D4BLns5ZUC2e_epSDAjbcBEAEg_4rkIVD48qOg_v____8BYOXK5YO0DqAB18G47wPIAQGoAwHIA9MEqgSQAU_Qh_tamywdQGkNwGTzd-p579quKAaKmB7URA4vBbSSNowmyAPqkiEAu6Kc19v81qaYEP1y6MKjVfCyU_9UUngwCtz1SlNgn3V046qTBrhENPMOvUYR09vg60QcWi-H2ABaXa2Kz8mlPnBJjaE2E7q43uB0MEBvG4u7MiS6xsYi4clKQSzksUFkrfKSZQEoeYAHkb7HEA&num=1&sig=AOD64_3waxyz_TRX1NMyIpx09jSJyJz-MA&client=ca-pub-9007421361448641&adurl=http://www.slideshare.net/about/workatslideshare&nm=3http://www.programiz.com/http://www.programiz.com/c-programming/exampleshttp://www.programiz.com/c-programming/library-functionhttp://www.programiz.com/c-programming/c-preprocessor-macroshttp://www.programiz.com/c-programming/c-enumerationhttp://www.programiz.com/c-programming/c-file-exampleshttp://www.programiz.com/c-programming/c-file-input-outputhttp://www.programiz.com/c-programming/c-structure-exampleshttp://www.programiz.com/c-programming/c-unionshttp://www.programiz.com/c-programming/c-structure-functionhttp://www.programiz.com/c-programming/c-structures-pointershttp://www.programiz.com/c-programming/c-structureshttp://www.programiz.com/c-programming/c-string-exampleshttp://www.programiz.com/c-programming/string-handling-functionshttp://www.programiz.com/c-programming/c-stringshttp://www.programiz.com/c-programming/c-pointer-exampleshttp://www.programiz.com/c-programming/c-dynamic-memory-allocationhttp://www.programiz.com/c-programming/c-pointer-functionshttp://www.programiz.com/c-programming/c-pointers-arrayshttp://www.programiz.com/c-programming/c-pointershttp://www.programiz.com/c-programming/c-arrays-exampleshttp://www.programiz.com/c-programming/c-arrays-functionshttp://www.programiz.com/c-programming/c-multi-dimensional-arrayshttp://www.programiz.com/c-programming/c-arrayshttp://www.programiz.com/c-programming/c-functions-exampleshttp://www.programiz.com/c-programming/c-storage-classhttp://www.programiz.com/c-programming/c-recursionhttp://www.programiz.com/c-programming/types-user-defined-functionshttp://www.programiz.com/c-programming/c-user-defined-functionshttp://www.programiz.com/c-programming/c-functionshttp://www.programiz.com/c-programming/c-decision-making-loops-exampleshttp://www.programiz.com/c-programming/c-goto-statementhttp://www.programiz.com/c-programming/c-switch-case-statementhttp://www.programiz.com/c-programming/c-break-continue-statementhttp://www.programiz.com/c-programming/c-do-while-loopshttp://www.programiz.com/c-programming/c-for-loophttp://www.programiz.com/c-programming/c-if-else-statementhttp://www.programiz.com/c-programming/c-introduction-exampleshttp://www.programiz.com/c-programming/precedence-associativity-operatorshttp://www.programiz.com/c-programming/c-operatorshttp://www.programiz.com/c-programming/c-input-outputhttp://www.programiz.com/c-programming/c-data-typeshttp://www.programiz.com/c-programming/c-variables-constantshttp://www.programiz.com/c-programming/c-keywords-identifierhttps://plus.google.com/111117167860655769030http://www.twitter.com/programizhttp://www.facebook.com/programizhttps://twitter.com/intent/follow?original_referer=http%3A%2F%2Fwww.programiz.com%2Fc-programming%2Fc-storage-class®ion=follow_link&screen_name=programiz&tw_p=followbutton&variant=2.0http://www.programiz.com/cpp-programminghttp://www.programiz.com/c-programminghttp://www.programiz.com/ -
7/27/2019 C Programming Storage Class
2/2
Recursive Function Function Examples
If the compiler encounters register variable, it tries to store variable in microprocessor's register rather than memory.
Value stored in register are much faster than that of memory.
In case of larger program, variables that are used in loops and function parameters are declared register variables.
Since, there are limited number of register in processor and if it couldn't store the variable in register, it will
automatically store it in memory.
Static Storage ClassThe value of static variable persists until the end of the program. A variable can be declared static using keyword:
static. For example:
static int i;
Here, i is a static variable.
Example to demonstrate the static variable
#include
voidCheck();
int main(){
Check();
Check();
Check();
}
voidCheck(){
static int c=0;
printf("%d\t",c);
c+=5;
}
Output
0 5 10
During first function call, it will display 0. Then, during second function call, variable c will not be initialized to 0
again, as it is static variable. So, 5 is displayed in second function call and 10 in third call.
If variable c had been automatic variable, the output would have been:
0 0 0
FROM 1,500
Scanner
FROM 2,000
Core Processor
FROM 8,000
Acer Laptop
Rexel Filing Cabinets
www.rexelindustries.com
Quality Steel Filing cabinets & Office Filing cabinets made in UAE
Like 0
Copyright programiz.com, 2011-2013 | All rights reserved | Google+
googleplus stumbleupon
https://plus.google.com/116050874615553634748?rel=authorhttp://www.google.com/url?ct=abg&q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://www.programiz.com/c-programming/c-storage-class%26gl%3DIN%26hl%3Den%26client%3Dca-pub-9007421361448641%26ai0%3DCvQxoYkzuUc6uKKy7igez-ICoB-Ttp5gD3OLXzFjAjbcBEAEg_4rkIVCa0eGg-v____8BYOXK5YO0DsgBAakC4V3k_lZFkj6oAwHIA9MEqgSNAU_QLpLTn__-VY1Ddvzm5v0Zk_S0cRYpx6lRngg5eCPMNN2icWjm9WTazLDH2w8QaK-CqB5lGcXffn24d4durEQdF7SnqxVnSPK5f3HbGXKkkQNyO3g18tNYAqvtmzdD98wTxUUwH7-DiehLH48IeitIu1ytQUR0LCkMTZTNNQOtex8lawy3VF3AZVrTdoAHnK27Hg&usg=AFQjCNEFdCkDEkaVrfhDarL4J2rWfIjsOwhttp://googleads.g.doubleclick.net/aclk?sa=L&ai=CvQxoYkzuUc6uKKy7igez-ICoB-Ttp5gD3OLXzFjAjbcBEAEg_4rkIVCa0eGg-v____8BYOXK5YO0DsgBAakC4V3k_lZFkj6oAwHIA9MEqgSNAU_QLpLTn__-VY1Ddvzm5v0Zk_S0cRYpx6lRngg5eCPMNN2icWjm9WTazLDH2w8QaK-CqB5lGcXffn24d4durEQdF7SnqxVnSPK5f3HbGXKkkQNyO3g18tNYAqvtmzdD98wTxUUwH7-DiehLH48IeitIu1ytQUR0LCkMTZTNNQOtex8lawy3VF3AZVrTdoAHnK27Hg&num=1&sig=AOD64_3gOm8QDQueK6Ou3NzBmjjLCRmBQQ&client=ca-pub-9007421361448641&adurl=http://www.rexelindustries.com/UAE-Filing-Cabinets.htmlhttp://www.programiz.com/c-programming/c-functions-exampleshttp://www.programiz.com/c-programming/c-recursion