![]() |
Data Types |
When you declare a variable, as mentioned already, the compiler reserves a space in memory for that variable in the stack. In most languages, that space is left empty until you put a value in it. Initialization is a technique of putting a value into the space memory of a variable. We also state that variable is assigned a value. To control the behavior of your program, you can assign the desired value to a variable when you declare it. That is, you can initialize a variable when declaring it. There are two main techniques used to initialize a variable. You can use the equal symbol (also called the assignment operator) to initialize a variable. To do that, after typing the name of the variable, type = followed by the desired value. The formula used would be: TypeOfVariable VariableName = InitialValue; Another technique of initializing a variable is by using parentheses. The syntax is: TypeOfVariable VariableName(InitialValue);
If many different variables are using the same data type, you can declare them on the same line, separating two with a comma, except the last one that would end with a semi-colon. The formula to follow is: DataType Variable1, Variable2, Variable3;
|
|
||
Previous | Copyright © 2006-2016, FunctionX, Inc. | Next |
|