PAPER: INTRODUCTION PROGRAMMING LANGUAGE USING C
PAPER ID: 20105
PAPER CODE: BCA 105
DR. VARUN TIWARI
(ASSOCIATE PROFESSOR)
(DEPARTMENT OF COMPUTER SCIENCE)
BOSCO TECHNICAL TRAINING SOCIETY,
DON BOSCO TECHNICAL SCHOOL, OKHLA ROAD , NEW DELHI
C STORAGE CLASS
OBJECTIVES
IN THIS UNIT YOU WILL LEARN:
1. TO UNDERSTAND ABOUT STORAGE CLASS IN C.
2. TO LEARN ABOUT WHY WE USE STORAGE CLASS.
3. TO LEARN ABOUT AUTOMATIC STORAGE CLASS.
4. TO LEARN ABOUT REGULAR STORAGE CLASS.
5. TO LEARN ABOUT STATIC STORAGE CLASS IN C.
6. TO LEARN ABOUT EXTERNAL STORAGE CLASS IN C.
STORAGE CLASS: WE CAN CHARACTERIZE VARIABLE IN TWO DIFFERENT WAYS:
1. DATA TYPE
2. STORAGE CLASS
STORAGE CLASS REFER TO THE PERFORMANCE OF VARIABLE AND ITS SCOPE WITH IN THE PROGRAM. THE
SCOPE WITH USE THE PROGRAM MEANS THE POSITION OF THE PROGRAM OVER WHICH THE VARIABLE IS
RECOGNIZED. A VARIABLE STORAGE CLASSES TELLS US:
1. WHERE THE VARIABLE WOULD BE STORED.
2. WHAT WOULD BE THE DEFAULT INITIAL VALUE OF THE VARIABLE.
3. WHAT IS THE SCOPE OF THE VARIABLE; I.E IN WHICH FUNCTIONS THE VALUE OF THE VARIABLE WOULD
BE AVAILABLE.
4. WHAT IS THE LIST OF THE VARIABLE; IE HOW LONG WOULD THE VARIABLE EXIST.
THERE ARE FOUR STORAGE CLASS IN C:
1. AUTOMATIC STORAGE CLASS
2. EXTERNAL STORAGE CLASS
3. STATIC STORAGE CLASS
4. REGISTER STORAGE CLASS
1. AUTOMATIC STORAGE CLASS: (VARIABLE LOCAL): WHEN WE PASS ARGUMENTS TO A FUNCTION WE ARE
ACTUALLY FUNCTION COPY OF THE VALUE WITH IN THE VARIABLE. SUCH VALUE MUST BE PLACED IN THE
VARIABLE WITH IN THE CALLED FUNCTION. EACH TIME THE FUNCTION IS CALLED VARIABLE ARE CREATED BY THE
SYSTEM TO STORE THESE VALUE. THE VARIABLE ARE TERM AUTOMATIC BECAUSE THEY ARE CREATED
AUTOMATICALLY WITH EACH CALLED TO THE FUNCTION SO AUTOMATIC VARIABLE ARE ALWAYS VARIABLE
DECLARED WITH IN THE FUNCTION ARE LOCAL TO THE FUNCTION IN WHICH THEY ARE DECLARED AND THESE
VARIABLE ARE DESTROY AUTOMATICALLY, WHENEVER CONTROL RETURN BACK TO THE MAIN FUNCTION. THE
SPECIFICATION OF THE KEYWORD AUTO AT THE BEGINNING OF EACH LOCAL VARIABLE DECALARATION AUTO IS
OPTIONAL KEYWORD. THE FEATURES OF AN AUTOMATIC STORAGE CLASS VARIABLE ARE AS UNDER:
STORAGE: MEMORY
DEFAULT VALUE: AN UNPREDICTABLE VALUE, OFTEN CALLED A GARBAGE VALUE.
SCOPE: LOCAL TO THE BLOCK IN WHICH THE VARIABLE IS DEFINED.
LIFE: TILL THE CONTROL REMAINS WITHIN THE BLOCK IN WHICH THE VARIABLE IS DEFINED.
EX-:
void main()
{
auto int p,q;
clrscr();
printf("enter two number-:");
scanf("%d%d",&p,&q);
printf("output is -%d%d",p,q);
getch();
}
2. EXTERNAL STORAGE CLASS: (VARIABLE GLOBAL): EXTERNAL VARIABLE ARE NOT BOUND TO A SINGLE
FUNCTION. EXTERNAL VARIABLE REMAIN COMMON FOR ALL THE FUNCTION WITH IN THE SAME PROGRAM.
THESE EXTERNAL VARIABLE ARE ALSO CALLED GLOBAL VARIABLE. THE EXTERNAL VARIABLE CAN BE ASSIGN
A VALUE WITH IN ONE FUNCTION AND THAT VALUE CAN BE USED WITH IN ANOTHER FUNCTION SO THE
SCOPE OF EXTERNAL VARIABLE EXTEND FROM THE POINT OF DEFINITION THROUGH THE REMAINDER OF
THE PROGRAM. WE HAVE TO USE EXTERN KEYWORD OF THE DECLARATION OF GLOBAL VARIABLE. IT IS AN
OPTIONAL KEYWORD.
THE FEATURES OF AN EXTERNAL STORAGE CLASS VARIABLE ARE AS FOLLOWS:
STORAGE: MEMORY
DEFAULT VALUE: NOT ZERO
SCOPE: GLOBAL
LIFE: AS LONG AS THE PROGRAM’S EXECUTION DOES NOT COME TO AN END.
3. STATIC STORAGE CLASS: C PROVIDE FOR ANOTHER CLASS OF VARIABLE ALL STATIC VARIABLE. THE
STORAGE CLASS FOR HAVE EITHER AN EXTERNAL OR INTERNAL FORM. THE EITHER CASE VARIABLE OF THIS
CLASS MUST BE DECLARED USING THE KEYWORD STATIC. THE SCOPE OF STATIC VARIABLE DIFFER
DEPENDING ON WHETHER KEY ARE EXTERNAL AND INTERNAL. IN STATIC STORAGE CLASS ONLY , IF YOU
WANT THE VALUE OF A VARIABLE TO PERSIST BETWEEN DIFFERENT FUNCTION CALLS. A TYPICAL
APPLICATION OF THIS STORAGE CLASS IS RECURSIVE FUNCTION.
THE FEATURES OF AN STATIC STORAGE CLASS VARIABLE ARE AS FOLLOWS:
STORAGE: MEMORY
DEFAULT VALUE: ZERO
SCOPE: LOCAL TO THE BLOCK IN WHICH THE VARIABLE IS DEFINED.
LIFE: VALUE OF THE VARIABLE PERSISTS BETWEEN DIFFERENT FUNCTION CALLS.
4. REGISTER STORAGE CLASS: USE REGISTER STORAGE CLASS FOR ONLY THOSE VARIABLE WHICH ARE
BEING USED VERY OFTEN IN A PROGRAM REASON IS, THERE ARE VERY FEW CPU REGISTER AT OUR
DISPOSAL AND MANY OF THEM MIGHT BE BUSY DOING SOMETHING ELSE. A VALUE STORED IN A CPU
REGISTER CAN ALWAYS BE ACCESSED FASTER THAN THE ONE WHICH IS IN THE STORING MEMORY.
THEREFORE IF A VARIABLE IS USED AT MANY PLACES IN A PROGRAM. IT IS BETTER TO DECLARED IT
STORAGE CLASS AS REGISTER. A FLOAT VALUE REQUIRES 4 BYTES , SO IT CAN NOT BE STORED IN A CPU
REGISTER. IF THE MICROPROCESSOR HAS 16-BIT CPU REGISTERS. IF YOU USE REGISTER STORAGE CLASS
FOR A FLOAT IN SUCH A CASE, YOU WOULD NOT GET ANY ERROR MESSAGE INSTEAD, THE COMPILER
WOULD TREAT IT AS AN AUTO STORAGE CLASS VARIABLE.
THE FEATURES OF AN REGISTER STORAGE CLASS VARIABLE ARE AS FOLLOWS:
STORAGE: CPU REGISTER
DEFAULT VALUE: GARBAGE VALUE
SCOPE: LOCAL TO THE BLOCK IN WHICH THE VARIABLE IS DEFINED.
LIFE: TILL THE CONTROL REMAINS WITHIN THE BLOCK IN WHICH THE VARIABLE IS DEFINED.
THANK YOU

C storage class

  • 1.
    PAPER: INTRODUCTION PROGRAMMINGLANGUAGE USING C PAPER ID: 20105 PAPER CODE: BCA 105 DR. VARUN TIWARI (ASSOCIATE PROFESSOR) (DEPARTMENT OF COMPUTER SCIENCE) BOSCO TECHNICAL TRAINING SOCIETY, DON BOSCO TECHNICAL SCHOOL, OKHLA ROAD , NEW DELHI
  • 2.
  • 3.
    OBJECTIVES IN THIS UNITYOU WILL LEARN: 1. TO UNDERSTAND ABOUT STORAGE CLASS IN C. 2. TO LEARN ABOUT WHY WE USE STORAGE CLASS. 3. TO LEARN ABOUT AUTOMATIC STORAGE CLASS. 4. TO LEARN ABOUT REGULAR STORAGE CLASS. 5. TO LEARN ABOUT STATIC STORAGE CLASS IN C. 6. TO LEARN ABOUT EXTERNAL STORAGE CLASS IN C.
  • 4.
    STORAGE CLASS: WECAN CHARACTERIZE VARIABLE IN TWO DIFFERENT WAYS: 1. DATA TYPE 2. STORAGE CLASS STORAGE CLASS REFER TO THE PERFORMANCE OF VARIABLE AND ITS SCOPE WITH IN THE PROGRAM. THE SCOPE WITH USE THE PROGRAM MEANS THE POSITION OF THE PROGRAM OVER WHICH THE VARIABLE IS RECOGNIZED. A VARIABLE STORAGE CLASSES TELLS US: 1. WHERE THE VARIABLE WOULD BE STORED. 2. WHAT WOULD BE THE DEFAULT INITIAL VALUE OF THE VARIABLE. 3. WHAT IS THE SCOPE OF THE VARIABLE; I.E IN WHICH FUNCTIONS THE VALUE OF THE VARIABLE WOULD BE AVAILABLE. 4. WHAT IS THE LIST OF THE VARIABLE; IE HOW LONG WOULD THE VARIABLE EXIST.
  • 5.
    THERE ARE FOURSTORAGE CLASS IN C: 1. AUTOMATIC STORAGE CLASS 2. EXTERNAL STORAGE CLASS 3. STATIC STORAGE CLASS 4. REGISTER STORAGE CLASS 1. AUTOMATIC STORAGE CLASS: (VARIABLE LOCAL): WHEN WE PASS ARGUMENTS TO A FUNCTION WE ARE ACTUALLY FUNCTION COPY OF THE VALUE WITH IN THE VARIABLE. SUCH VALUE MUST BE PLACED IN THE VARIABLE WITH IN THE CALLED FUNCTION. EACH TIME THE FUNCTION IS CALLED VARIABLE ARE CREATED BY THE SYSTEM TO STORE THESE VALUE. THE VARIABLE ARE TERM AUTOMATIC BECAUSE THEY ARE CREATED AUTOMATICALLY WITH EACH CALLED TO THE FUNCTION SO AUTOMATIC VARIABLE ARE ALWAYS VARIABLE DECLARED WITH IN THE FUNCTION ARE LOCAL TO THE FUNCTION IN WHICH THEY ARE DECLARED AND THESE VARIABLE ARE DESTROY AUTOMATICALLY, WHENEVER CONTROL RETURN BACK TO THE MAIN FUNCTION. THE SPECIFICATION OF THE KEYWORD AUTO AT THE BEGINNING OF EACH LOCAL VARIABLE DECALARATION AUTO IS OPTIONAL KEYWORD. THE FEATURES OF AN AUTOMATIC STORAGE CLASS VARIABLE ARE AS UNDER:
  • 6.
    STORAGE: MEMORY DEFAULT VALUE:AN UNPREDICTABLE VALUE, OFTEN CALLED A GARBAGE VALUE. SCOPE: LOCAL TO THE BLOCK IN WHICH THE VARIABLE IS DEFINED. LIFE: TILL THE CONTROL REMAINS WITHIN THE BLOCK IN WHICH THE VARIABLE IS DEFINED. EX-: void main() { auto int p,q; clrscr(); printf("enter two number-:"); scanf("%d%d",&p,&q); printf("output is -%d%d",p,q); getch(); }
  • 8.
    2. EXTERNAL STORAGECLASS: (VARIABLE GLOBAL): EXTERNAL VARIABLE ARE NOT BOUND TO A SINGLE FUNCTION. EXTERNAL VARIABLE REMAIN COMMON FOR ALL THE FUNCTION WITH IN THE SAME PROGRAM. THESE EXTERNAL VARIABLE ARE ALSO CALLED GLOBAL VARIABLE. THE EXTERNAL VARIABLE CAN BE ASSIGN A VALUE WITH IN ONE FUNCTION AND THAT VALUE CAN BE USED WITH IN ANOTHER FUNCTION SO THE SCOPE OF EXTERNAL VARIABLE EXTEND FROM THE POINT OF DEFINITION THROUGH THE REMAINDER OF THE PROGRAM. WE HAVE TO USE EXTERN KEYWORD OF THE DECLARATION OF GLOBAL VARIABLE. IT IS AN OPTIONAL KEYWORD. THE FEATURES OF AN EXTERNAL STORAGE CLASS VARIABLE ARE AS FOLLOWS: STORAGE: MEMORY DEFAULT VALUE: NOT ZERO SCOPE: GLOBAL LIFE: AS LONG AS THE PROGRAM’S EXECUTION DOES NOT COME TO AN END.
  • 10.
    3. STATIC STORAGECLASS: C PROVIDE FOR ANOTHER CLASS OF VARIABLE ALL STATIC VARIABLE. THE STORAGE CLASS FOR HAVE EITHER AN EXTERNAL OR INTERNAL FORM. THE EITHER CASE VARIABLE OF THIS CLASS MUST BE DECLARED USING THE KEYWORD STATIC. THE SCOPE OF STATIC VARIABLE DIFFER DEPENDING ON WHETHER KEY ARE EXTERNAL AND INTERNAL. IN STATIC STORAGE CLASS ONLY , IF YOU WANT THE VALUE OF A VARIABLE TO PERSIST BETWEEN DIFFERENT FUNCTION CALLS. A TYPICAL APPLICATION OF THIS STORAGE CLASS IS RECURSIVE FUNCTION. THE FEATURES OF AN STATIC STORAGE CLASS VARIABLE ARE AS FOLLOWS: STORAGE: MEMORY DEFAULT VALUE: ZERO SCOPE: LOCAL TO THE BLOCK IN WHICH THE VARIABLE IS DEFINED. LIFE: VALUE OF THE VARIABLE PERSISTS BETWEEN DIFFERENT FUNCTION CALLS.
  • 15.
    4. REGISTER STORAGECLASS: USE REGISTER STORAGE CLASS FOR ONLY THOSE VARIABLE WHICH ARE BEING USED VERY OFTEN IN A PROGRAM REASON IS, THERE ARE VERY FEW CPU REGISTER AT OUR DISPOSAL AND MANY OF THEM MIGHT BE BUSY DOING SOMETHING ELSE. A VALUE STORED IN A CPU REGISTER CAN ALWAYS BE ACCESSED FASTER THAN THE ONE WHICH IS IN THE STORING MEMORY. THEREFORE IF A VARIABLE IS USED AT MANY PLACES IN A PROGRAM. IT IS BETTER TO DECLARED IT STORAGE CLASS AS REGISTER. A FLOAT VALUE REQUIRES 4 BYTES , SO IT CAN NOT BE STORED IN A CPU REGISTER. IF THE MICROPROCESSOR HAS 16-BIT CPU REGISTERS. IF YOU USE REGISTER STORAGE CLASS FOR A FLOAT IN SUCH A CASE, YOU WOULD NOT GET ANY ERROR MESSAGE INSTEAD, THE COMPILER WOULD TREAT IT AS AN AUTO STORAGE CLASS VARIABLE. THE FEATURES OF AN REGISTER STORAGE CLASS VARIABLE ARE AS FOLLOWS: STORAGE: CPU REGISTER DEFAULT VALUE: GARBAGE VALUE SCOPE: LOCAL TO THE BLOCK IN WHICH THE VARIABLE IS DEFINED. LIFE: TILL THE CONTROL REMAINS WITHIN THE BLOCK IN WHICH THE VARIABLE IS DEFINED.
  • 19.