answersLogoWhite

0

Variables can maintain the same value throughout a program, or they can change values several times, depending on your needs. when you put a variable in a program, the computer recognises the variable and you can change it's value throughout without an error. Note: You can write programs without variables, but their functionality will be quite restricted, like this:

int main (void) { puts ("hello, world"); return 0; }

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
More answers

In any progarm we typically do lots of calculations.

The results of these calculations are stored in computer's memory.

Like human memory, the computer's memory also consists of millions of cells.

The calculated values are stored in these memory cells.

To make the retrieval usage of these values easy these memory cells also called memory locations are given names.

The names called Variable names.

User Avatar

Wiki User

15y ago
User Avatar

Mainly, use to store data.

variable is just like a data structure.

we save our values and data in variables to operate them.

we can make our programs without variables variables but in a very restricted way.

variable are vry important in our programs.

User Avatar

Wiki User

13y ago
User Avatar

When programming, if variables aren't used, a program is quite literally 1 dimensional, if you were to make a calculator, you would have to reprogram it every time you wanted to calculate something. Eg:

say you wanted to work out 5 by 5, (In batch programming, in this scenario)

your program would look something like this:

@echo off

set /a answer=5*5

echo %answer%

pause

Notice that even then you need to make a variable for calculations, but that is due to the simplicity and convenience of batch.

This program would set a variable to 5 multiplied by 5 and then display that variable using echo %answer%

pause just means it would wait for you to 'press any key to continue' and then close.

However, say you wanted 7 times that amount in the end, you would have to remake the program.

@echo off

set /a answer=5*5*7

echo %answer%

pause

So if you were to make a program that involved variables (In terms of a normal programming language) it would be a lot more convenient:

@echo off

set /p A=Define first variable. ;Sorry about the pun

set /p B=Define second variable

set /p op=Define operation (+ - * % or /)

set /a answer=%A%%op%%B%

echo

This program would ask you to define each of the variables before making and algorithm out of those variables to calculate and then display.

Variables are the first step into making a smarter and efficient program that is either more user friendly or can judge it surroundings to work out how to get around some of the more complicated problems in life.

User Avatar

Wiki User

14y ago
User Avatar

Advantages of Variable in Programming.As we know that Variable is a place where data is stored and retrieved while its is required. In the context of Programming, we must have to create a variable to store our input data for processing. we can point out its advantages as below.
  • Variable helps us to store data
  • Data stored in variable may be String or Numeric.
  • Variable also can store Constants that can be changed during program execution.

Mr. Gauro

Nepal Engineering and Technical Science Academy.

Birendranagar, surkhet

Nepal

User Avatar

Wiki User

13y ago
User Avatar

A variable is an object we use to store and manipulate information. Variables are either constant or mutable. A constant variable cannot (easily) change value once initialised whereas a mutable variable's value can always be changed at any time, or it can be left uninitialised. All variables can be copied and mutable variables can also be moved.

Variables can be named at design time however variables allocated on the heap are generated at runtime and therefore cannot be named; they are anonymous. However, all variables have an address thus we can refer to them by that address.

Variables passed to functions are always passed by value which means the value is copied and assigned to the function's formal argument, which is another variable. However, if we wish to pass the variable itself, rather than it's value, then we must pass the variable by reference, which means we pass the address of the variable rather than its value. To pass an address into a function, the function's formal argument must be a reference or pointer variable. A pointer variable is a special type of variable that is used purely to store a memory address and refer to the value stored at that address (also known as pointer dereferencing). A reference is not a variable, it is merely an alias (an alternate name) for a variable, in the same way that Tom is an alternate for someone called Thomas (they both refer to the same person).

User Avatar

Wiki User

7y ago
User Avatar

Without variables, programs would not be able accept or process user data. In essence, a new program would have to be written each time new data was used, which would make software useless. Variables allow programmers to input data from keyboards, mice, networks, and so on, and output data to screens, printers, and so on. Variables are one of the key elements of programming, which without programs could never be useful.

User Avatar

Wiki User

11y ago
User Avatar

Storing data, especially variable (ie not constant) data.

User Avatar

Wiki User

15y ago
User Avatar

Strictly speaking, you are not bound to use variables, but they can be very useful in programming.

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Why does programmer need variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp