• Discussion Fanatics

    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.

  • Discussion Fanatics

    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.

What is discussplaces?

DiscussPlaces is a place to make new friends and share your passions and interests. Quench your thirst for knowledge, discuss places with other aficionados, and swap recommendations. Are you an aspiring foodie who dreams of living in New York? Or perhaps you are looking for the best chicken wings in Cincinnati? Then this is the place for you! Any one can join in with a passion or interest – whether it be talking about their favorite restaurant in Barcelona or raving about their latest trip to Italy. Join us!



This page shows discussions around "Can static variables be changed in C?"

Tags

technology and computing programming languages static variable variable global variables static global

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?