English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

What is Variable and what are rules for defining a variable in C/C++.

2007-03-29 18:55:08 · 6 answers · asked by hafsa a 1 in Computers & Internet Programming & Design

6 answers

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)

2007-03-29 20:18:15 · answer #1 · answered by Silver_Sword 3 · 0 0

variable is a knowledge member of this methodology. it have a form meaning the shape of archives it shops (integer huge type, personality etc.) and scope meaning the position that's existed (international or interior of reach). the style is defined interior the line: type ; as an instance: int i; unsigned char letter; the scope is defined by technique of were the line of the statement is placed interior the code. if the definition is exterior the applications that's international variable the this variable is international, if the statement is in a function then the variable is defined purely in this function. in C the statement should be on the starting up of the code executed between the "{" and the code. int C++ it can be everywhere interior the code.

2016-12-03 00:28:10 · answer #2 · answered by aoay 4 · 0 0

The dictionary defines variable as
adjective:-
likely to change frequently:
or
noun [C] SPECIALIZED
a number, amount or situation which can change:

In computing terms a variable is a predefined type of memory allocation that can and probably will change its value.

2007-03-29 20:18:18 · answer #3 · answered by AnalProgrammer 7 · 0 0

a variable is like a box that contains a specific value,
u can use it or modify it.
there r 2 types of variable : global and local
and there r variables that can be as parameters that enter & leave a specific function.

2007-03-29 19:09:56 · answer #4 · answered by 14Me14U 2 · 0 0

variable is name of a block of memory address

2007-03-29 19:32:00 · answer #5 · answered by Anonymous · 0 0

there's a tutorial on www.functionx.com for C/C++

2007-03-29 21:10:59 · answer #6 · answered by sleepyhead 2 · 0 0

fedest.com, questions and answers