A variable lets us store names that our programs can manipulate. Each C++ variable has a particular type that defines the variable's memory size and layout, the range of values that can be saved in that memory, and the set of operations used for the variable.
The variable name can be letters, numbers, and the underscore character. It should start with either a letter or an emphasis. The letters in the upper and lower case are different because C++ is case sensitive −
As mentioned in the last chapter, there are the following primary forms of vary in C++ -
C++ also enables the definition of several variable kinds, including listing, display, array, reference, data structure, and classes, which can be covered in the following chapters.
The following section will discuss how various variables can be defined, declared, and used.
A definition variable instructs the compiler where and how much storage the variable needs to create. A variable definition identifies a type of data and includes the following list of one or more variables of that type –
type variable_list;
A variable statement assures the compiler that a variable exists with the supplied type and name. The compiler continues compiling without any details of the variable being needed. A variable statement has its significance at the time of compilation alone; the compiler requires the real variable definition when the program is linked.
When you use many files, a variable declaration is helpful, and you specify your variable in one of the files available when the program is connected. To declare a variable in any place using an external keyword. Although a variable can be declared numerous times in your C++, it can only be defined once in a single file, function, or code block.
*Note :- variable also declare without assigning the value, or you can assign the value later:
|