Variables

A variable is simply an identifying name for a memory address.

 

A bit like a telephone book, where names are matched to numbers. After-all, it's much easier for us humans to work with names than having to deal with large and complex hexadecimal numbers.

 

 

The data type of a variable simply tells the compiler how much memory space to allocate.

 

So, given that an int takes four bytes, and if it were assigned a memory address of 0x00002010, the next available memory address would be 0x00002014.

 

Similarly, an array is assigned [N] memory allocations for its datatype, and so on for structs, unions, classes, etc.

 

So a variable is simply a name for the starting memory location for the object being declared.

 

Variables (or any other type of object) can be thought of as containers of specified information. If instructed, this information can be changed and the contents of that container will reflect the instructed change.

 

Being an Object Oriented language, the term object is generally interchangeably used in C++ when referring to variables, structs, unions, objects that use identifiers to give them unique names.

Leave a Reply