Skip to content
Skins
  • Light
  • Brite
  • 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
DiscussPlaces
DiscussPlaces
Destinations Popular Recent City guides Chat
Log in Join free New topic
  1. Discussions around everything
  2. Categories
  3. United States
  4. Can static variables be changed in C?

Can static variables be changed in C?

Scheduled Pinned Locked Moved United States
technology and computingprogramming languagesstatic variablevariableglobal variablesstaticglobal
2 Posts 2 Posters 998 Views 2 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.
  • happyduck881H
    happyduck881H
    happyduck881
    Discussion Fanatics
    wrote on last edited by
    #1

    You can declare a static variable in a C function. This variable is only visible in the function however it behaves like a global in that it is only initialized once and it retains its value. In this example, everytime you call foo() it will print an increasing number. The static variable is initialized only once.

    1 Reply Last reply
    0
    • bigbird816B
      bigbird816B
      bigbird816
      Discussion Fanatics
      wrote on last edited by
      #2

      It is a static variable so you wont need any object of class in order to access it. Its final so the value of this variable can never be changed in the current or in any class.

      Beside above, can global variables be changed in C? Global Variables They are not limited to any function. Any function can access and modify global variables. Global variables are automatically initialized to 0 at the time of declaration. Global variables are generally written before main() function.

      Also asked, can we change value of static variable in C?

      again, reason is static variable is initialized once, when next time main() is called it will not be initialize to 5 because it is already initialized in the program.So we can change the value but can not reinitialized. Thats how static variable works.

      What does static variable mean in C?

      static is an access qualifier that limits the scope but causes the variable to exist for the lifetime of the program. This means a static variable is one that is not seen outside the function in which it is declared but which remains until the program terminates.

      1 Reply Last reply
      0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      New here?

      DiscussPlaces is where people swap honest notes about living in, visiting and studying in places around the world.

      Join free

      Related topics

      • What is MIB speed?
        0
        1
        626

      • Can you multiply radicals?
        organicbird383O
        organicbird383
        0
        2
        803

      • Can you still get Nextel?
        B
        bigleopard696
        0
        2
        978

      • Can I delete DS_Store?
        blackwolf811B
        blackwolf811
        0
        2
        1.1k

      • How do I connect PdaNet to my router?
        B
        brownswan195
        0
        2
        1.3k

      Trending this week

      Tags

      technology and computingprogramming languagesstatic variablevariableglobal variablesstaticglobal

      Whether the information provided was useful?

      Add a quick comment about your valuable suggestion to help us improve.




      We are glad to make you happy, kindly share this feedback with your friends and family to know as well


      Where is it?

      DiscussPlaces

      Honest conversations about places: living there, visiting, studying and eating well.

      Explore

      Countries and cities Popular topics Recent topics Tags

      Guides

      City guides Geography and facts World flags Ask a question

      Community

      Live chat Members Join free

      © DiscussPlaces AboutContactPrivacyTermsPhotos: Manarola by Timothy A. Gonsalves (CC BY-SA 4.0) and Lisbon by Dale Cruse (CC BY 4.0), via Wikimedia Commons.

      Live chat
      • Sound
      • Notification
      • Hide
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0