Results 1 to 4 of 4

Thread: Explain

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Answers
    6

    Explain

    explain about auto,register,static,extern


  2. #2
    Expert Member
    Join Date
    Jun 2007
    Answers
    260

    Re: Explain

    hi,

    Refer to the attachemnet

    Thanks
    Sushma

    Attached Files Attached Files

  3. #3
    Junior Member
    Join Date
    Dec 2006
    Answers
    12

    Re: Explain

    Quote Originally Posted by ks.dinesh View Post
    explain about auto,register,static,extern
    These four are known as storage classes,because they determine scope and lifetime of a variable.
    Scope means the range of statements in which the variable is valid and lifetime the duration for which the variable exists.
    Generally when we declare variables they are auto by default because their scope is confined to the closing brace from their point of declaration and lifetime as well and one cannot access those variables after the closing brace.
    It is same as auto but it uses processor registers instead of memory locations
    to speed up processing.
    One more thing both contains garbage value if not supplied with any intial value.
    static is somehow different.it is intialised to zero if not supplied with any intial value.Its scope is same as that of auto but its life time is the entire program and it retains its value between successive function call.
    The scope of external variables is global, i.e. the entire source code in the file following the declarations


  4. #4
    Expert Member
    Join Date
    Apr 2008
    Answers
    1,859

    Re: Explain

    hi friend

    Register variables are a special case of automatic variables. Automatic variables are allocated storage in the memory of the computer; however, for most computers, accessing data in memory is considerably slower than processing in the CPU. These computers often have small amounts of storage within the CPU itself where data can be stored and accessed quickly. These storage cells are called registers.

    Normally, the compiler determines what data is to be stored in the registers of the CPU at what times. However, the C language provides the storage class register so that the programmer can ``suggest'' to the compiler that particular automatic variables should be allocated to CPU registers, if possible. Thus, register variables provide a certain control over efficiency of program execution. Variables which are used repeatedly or whose access times are critical, may be declared to be of storage class register.

    Also these register variables are used in huge projects the tiny program developers are not interested to include these register variables, because the tiny programs never requires more time complete its job. These register variables may be used to store constant values so as to make use of it anywhere in the programs.

    main{ register float a=0;}

    static
    static is the default storage class for global variables.

    Extern
    The "extern" declaration in C is to indicate the existence of, and the type of, a global variable or function. A global variable, or a global function, is one that is available to all C modules (a single C module is typically a single .c file). An extern is something that is defined externally to the current module. In many cases, you can leave off the extern qualifier and not notice any difference because the linker can collapse multiple definitions to one. But the intent is then unclear in the code, and the code is error prone in case of typos. It is much clearer to define the global in one place, and then declare extern references to it in all the other places. When refering to globals provided by a library, especially a shared library, this is even more important in order to ensure you are talking about the correct, common instance of the variable.

    Declaring a variable as extern will result in your program not reserving any memory for the variable in the scope that it was declared. For instance (as example) if a program's source code declared the variable var as a global volatile int in foo.c, to properly use it in bar.c you would declare it as extern volatile int var.

    It is also not uncommon to find function prototypes declared as extern.

    auto
    It is a local variable known only to the function in which it is declared. Auto is the default storage class.

    Thanks
    Deepasree


  5.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact