- To create a variable first you define the data type.
- After this you define an unique name.
/* Without value assignment */
<data-type> <variable-name>;
/* With value assignment */
<data-type> <variable-name> = <variable-value>;
❖ For example, see the statement given below.
/* Variable declaration with value assignment */
int Age = 25;
- An integer variable has been created by this statement, which is named Age and this variable is assigned 25 values.
- Let us now understand how the compiler executes this statement.
- When the compiler first executes the int, it allot the memory of 2 bytes of the computer's memory.
- After this, when the compiler executes the age, it gives the name of memory of that 2 bytes to age.
- After this, when compiler = 25 executes, then he stores 25 on this memory location.
❖ Now whenever you want to access this value, you can access it by age name.
No comments:
Post a Comment
Please do not any spam link in Comment Box