Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. static variable Vs Global Variable

static variable Vs Global Variable

Scheduled Pinned Locked Moved C / C++ / MFC
questionvisual-studio
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Game point
    wrote on last edited by
    #1

    Hello Sir What is the main difference of static variable and Global Variable? My Suggestion is : Static variable accessing only through out the class and accessing need for scope resolution operator Global variable accessing through out the program and accessing the class object. Sir, My statements are correct or not

    :~ Failure is Success If we learn from it!!:~

    R _ 2 Replies Last reply
    0
    • G Game point

      Hello Sir What is the main difference of static variable and Global Variable? My Suggestion is : Static variable accessing only through out the class and accessing need for scope resolution operator Global variable accessing through out the program and accessing the class object. Sir, My statements are correct or not

      :~ Failure is Success If we learn from it!!:~

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      Scoping is possible with a static variable (I'm not talking about a data member of a class, but in general). You could put a static variable within a function and have it retain its value through the life of the program, but the scope is restricted - code from outside the function where it's declared cannot change it. A static global variable (global scope, but declared as static) is not visible outside the source file where it exists. You got it right about a static data member.

      “Follow your bliss.” – Joseph Campbell

      1 Reply Last reply
      0
      • G Game point

        Hello Sir What is the main difference of static variable and Global Variable? My Suggestion is : Static variable accessing only through out the class and accessing need for scope resolution operator Global variable accessing through out the program and accessing the class object. Sir, My statements are correct or not

        :~ Failure is Success If we learn from it!!:~

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        Just for the sake of completeness, static is only understood by the compiler to scope the entity. For the system, it is exactly the same as a global variable. So if you're using an assembler to write programs, you do not have the luxury of static and you have to do the scoping yourself.

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups