Chapter 2.4 - Discuss How Variables Are Used In A Program | Part - 3


DECLARATION OF STORAGE CLASS

Variables in C can have not only data type but also storage class that provides information about their location and visibility. The storage class decides the portion of the program within which the variables are recognized. Consider the following example:


             Download Turbo C++ Program Program Complier                                                                                    

DECLARATION OF STORAGE CLASS

/* Example of storage classes */
int m;                                 
main()                                
{                                          
     int i;                            
    float balance;          
.....                          
.....                          
     functions1();            
}                                        
             function1()                        
{                                         
int i;                       
  float sum;               
.....                          
.....                          
}            


The variable m which has been declared before the main is called a global variable. It can be used in all the functions in the program. It need not be declared in the functions. A global variable is also known as an external variable. 

           C Numbers Pattern Programs With Easy Solutions

           C Star Pattern Programs With Easy Solutions
                  
The variables i, balance and sum are called local variables because they are declared insides a function. Local variables are visible and meaningful only inside the functions in which they are declared.

They are not known to other functions. Note that the variable i has been declared in both the functions. Any change in the value of i in one function does not affect its value in the other.       
C provides a variety of storage class specifiers that can be used to declare explicitly the scope and lifetime of variables. The concepts of scope and lifetime are important only in multifunction and multiple file programs and therefore the storage classes are considered in detail later when functions are discussed. For now, remember that there are storage class specifiers (auto, register, static and extern) whose meanings are given in Table 2.10.

The storage class is another qualifier (like long or unsigned) that can be added to a variable declaration as shown below:

auto int count;        
register char ch;      
static int x;           
extern long total ;  

Static and external (extern) variables are automatically initialized to zero. Automatic (auto) variables contain undefined values (known as 'garbage') unless they are initialized explicitly.


DECLARATION OF STORAGE CLASS


Post a Comment

12 Comments

  1. Apply Indian Army – 10+2 TECHNICAL ENTRY SCHEME – 44 COURSE
    Click Here

    ReplyDelete
  2. How to Download Neet 2020 Exam Admit Card
    Download

    ReplyDelete
  3. IBPS Clerk Recruitment 2020 (1557) Post
    Apply Online

    ReplyDelete
  4. Download Free Latest Version of Windows 10 2020
    Download Windows 10 2020

    ReplyDelete
  5. Top 5 New Technology Trends for 2021
    Get Info

    ReplyDelete
  6. software developer jobs for freshers
    Click Here

    ReplyDelete
  7. Campus drive by Gridlogics Technologies | Software Engineering Jobs
    https://bit.ly/3xi4rdb

    ReplyDelete
  8. Campus drive by Gridlogics Technologies | Software Engineering Jobs
    Click Here

    ReplyDelete
  9. Download Free Windows 7 All Versions 32/64 Bit ISO July-2021
    Download

    ReplyDelete
  10. Mahavitaran (MSEB) Recruitment 2021 | Government Job
    Apply Now

    ReplyDelete
  11. Download Free Windows 7 Ultimate 32/64 Bit ISO May-2022
    Download Now

    ReplyDelete

Ask Me Everything About Programming.