answersLogoWhite

0


Best Answer

You can change a static variable by putting the static variable into a function that has operations that you intend to execute upon the variable. Example, you want to change the static variable to another value or make an addition of 2. Put the source code inside a function with the static variable declared locally within the function.

Every time you call the function, the static variable value will change. Take note that the static variable retains the last value you declared it in your function call.

A more terse answerLocal variables declared as static are changed as normal; they are special in that their values persist across function calls.
User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

There is no such thing as a constant variable. A value is either constant or it is variable, it cannot be both. To answer the question, a constant value cannot be changed anywhere in a C++ program. Only variable values can be changed.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

The answer is you cannot. The idea of constant is to prevent the value of the variable being changed at run time.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you change the value of a constant variable in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is a constant as used in C programming?

A variable of which the value cannot change. Example of its usage: const int foo = 5;


Is it necessary to initialize the const variable in c?

A constant variable cannot have its value changed at program run time.


What is micro and how it is different from c variable name?

A macro is a variable that has a constant value throughout the program whereas a C variable is an identifier whose value can differ from function to function, it can be incremented or decremented whereas the value of a macro remains same .


What is an alias name given to a variable in opp with c plus plus?

An alias is a reference, an alternate name for a variable or constant. You can assign the address of any variable or constant to a reference of the same type. A reference is a bit like a constant pointer to the type but, unlike a pointer, a reference has no address of its own thus you cannot store references. More importantly, references can never be NULL. They are simply an alternative name by which you can refer to an existing variable or constant. When you assign a value to an existing reference to a variable, you are assigning the value to the variable itself. When you pass a reference to a function, you are passing the address of the value being referred to, and that address is assigned to the function's reference argument and is local to the function. This is not unlike passing a pointer, but pointers may be NULL, references are guaranteed to be non-NULL (a NULL reference invalidates your program). Note that C++ references are not the same as C reference variables or constants. In C, a reference variable is simply a non-const pointer, while a reference constant is a constant pointer. Hence pointers can be dereferenced (both in C and C++). But in C++, a reference is neither a variable nor a pointer, but is constant (it always refers to the same object and cannot be reassigned once assigned).


Differentiate c constant and c variables?

Differentiate between constants and variableConstantsvariablescharacteristicsValue is not changeableduring the course of the programValue can be changedanytime during the course of the programusageUse constant when you want to declare something that won't change midway in your program execution.Use variable to store data thatmay or will change during the running of the program.

Related questions

What does a constant do in c plus plus?

A constant is a variable that does not change. The correct term is constant variable.


What is constant variable in c?

Constant variables refers to those variables whose values cannot be changed. These variables should be initialized along with their declaration. Attempt to change the value of a constant variable will generate compile error. The syntax for declaring a constant variable is:const data-type variableName = value;


What is a constant as used in C programming?

A variable of which the value cannot change. Example of its usage: const int foo = 5;


What is an integer constant in c plus plus?

A constant integer is an integer that is not expected to change value while it is in scope. Declaring any variable constant doesn't guarantee it won't change, but it does make it more difficult for a programmer to change the value by accident. Constant integers must be initialised at the point of instantiation. We can initialise a constant with the value of a literal constant, the value of another constant, or the value of a variable: void f (int v) { const int x {42}; // Integer constant (initialised from literal constant) const int y {x}; // Integer constant (initialised from another constant) const int z {v}; // Integer constant (initialised from a variable) // ... v *= 2; // ok -- v is variable x *= 2; // error: x is constant }


What do you understand by constant and variable in c plus plus program?

A variable is any named value of a specified type that can hold any value of that type, and that can change that value at any time while the name is in scope. A constant is exactly the same as a variable except that its value must be set at the point of instantiation and the given value cannot be altered while the name remains in scope. In other words, a variable is a value that may vary while a constant is a value that always remains the same.


How do you use define in C?

Just type declare then the variable that you desire to assigned a certain constant value on it. Just type declare then the variable that you desire to assigned a certain constant value on it.


Is it necessary to initialize the const variable in c?

A constant variable cannot have its value changed at program run time.


What is the difference between a variable and a non variable?

A variable changes. It varies. A non variable does not change. It is constant. For example if I write a mathematical expression such as x + 1, then x is a variable. Its value can be whatever value we choose. However 1 is a non variable. Its value is 1 and never changes from 1. In a scientific experiment a variable would be something that you changed from one test to another. A non variable would be something that remained constant from test to test. As a final example: the speed at which light travels in a vaccum is a constant. It is referred to by the letter c which stands for the universal constant. However, the speed at which your car travels is a variable. It changes.


What is micro and how it is different from c variable name?

A macro is a variable that has a constant value throughout the program whereas a C variable is an identifier whose value can differ from function to function, it can be incremented or decremented whereas the value of a macro remains same .


What does c equal?

In math, a number signified by "C" is a constant number. A constant is the opposite of a variable. While a variable changes, a constant will always stay the same. For example, in the equation y = 4x + 10, 10 is a constant. If you did not know the value of 10 (for example, if you had just integrated), it could be written as y = 4x + c.


Differentiate between C Constants and C variables?

A constant value cannot be changed once set. A variable can be changed whenever you want.


What is a C variable?

A variable is an entity that may change its value. In a program, the result of the processing statements are stored in the computer's memory.