Variables are like containers or holders of values. If you want to save an integer somewhere you have to assign it to a variable as such:
int someInteger = 4;
Now, here are some rules for defining a variable in C++:
1) The declaration of a variable consists of three parts (the type of the variable, the name of the variable, and the value you are assigning to the variable)
2) The name of the variable can't be a reserved word such as (string, int, double, this, class, main, return, etc.)
3) The value you assign to the variable has to be of the same type as the variable itself. Here are examples:
int a = 7; // this is good
double k = 2.4; // this is good
int c = 5.6; // this is bad because you are assigning a
// double to a variable of type int (integer)
I hope this helps!!
2007-03-20 19:54:52
·
answer #1
·
answered by Silver_Sword 3
·
0⤊
0⤋
variable is a data member of the program.
it have a type which means the kind of data it stores (integer number, character etc.) and scope which means where it is existed (global or local).
The type is defined in the line:
;
for example:
int i;
unsigned char letter;
the scope is defined by were the line of the declaration is positioned in the code.
if the definition is outside the functions it is global variable the this variable is global, if the declaration is in a function then the variable is defined only in this function.
in C the declaration must be at the beginning of the code executed between the "{" and the code. int C++ it can be anywhere in the code.
2007-03-20 18:10:20
·
answer #2
·
answered by eyal b 4
·
0⤊
0⤋
The dictionary defines variable as adjective:- likely to regulate many times: or noun [C] SPEd61f837cad1d412f80b84d143e1257IALIZED a tremendous decision, volume or problem that can replace: In computing words a variable is a predefined type of memory allocation that could and probably will replace its fee.
2016-12-02 08:16:03
·
answer #3
·
answered by ? 3
·
0⤊
0⤋
variable is name associated with memory addreses
so that you can access memory address using this name
2007-03-21 00:38:44
·
answer #4
·
answered by Anonymous
·
0⤊
0⤋
I hope, it will help:
http://en.wikipedia.org/wiki/Variable
2007-03-20 18:55:48
·
answer #5
·
answered by alakit013 5
·
0⤊
0⤋