none
Difference Between Global , extern global , static , static global

    Question

  • Hi,

      Please any one explain me about

          1. Global variable  (example :   int i_Global)

          2. Extern variable (example  :  extern  int i_Global)

          3. static variable  (example : static int i_Local means in .h file)

          4. static global variable ( example : static int i_Global)

     

    Friday, April 15, 2011 11:30 AM

Answers

  • 1. Defines a global variable, allocating memory for it which will be accessible by all files in the program.

    2. Declares a global variable which is defined in another file. No memory is allocated. This is how global variables defined in one file can be used in another.

    3. static local variables retain their values on repeated calls into the function unlike other local variables.

    4. These global variables can only be accessed from within the file. Using the static keyword you can declare global variables with the same name in multiple files in the same program.


    «_Superman_»
    Microsoft MVP (Visual C++)
    Friday, April 15, 2011 2:14 PM

All replies

  • Is this a class assignment?
    Friday, April 15, 2011 11:58 AM
  • 1. Defines a global variable, allocating memory for it which will be accessible by all files in the program.

    2. Declares a global variable which is defined in another file. No memory is allocated. This is how global variables defined in one file can be used in another.

    3. static local variables retain their values on repeated calls into the function unlike other local variables.

    4. These global variables can only be accessed from within the file. Using the static keyword you can declare global variables with the same name in multiple files in the same program.


    «_Superman_»
    Microsoft MVP (Visual C++)
    Friday, April 15, 2011 2:14 PM
  • Hi Megaau,

     

    Would you mind letting me know the result of the suggestions? If you need further assistance, feel free to let me know. I will be more than happy to be of assistance.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, April 18, 2011 3:51 AM