Local Variables in C++

Local variables are declared in methods and blocks. They are only accessible within that certain method or block.

dataType variableName;


C++ allows you to assign a value to the variable on creation. A default value (depending on the data type) is assigned if the program doesn't do so.

Local variables (also can be known as automatic or stack variables) are declared in the stack, which means their memory is allocated during compile time. Local variables directly manipulate contents of a memory location.

dataType can be one of the C++ fundamental data types or a user-defined data type.

int length = 5; //same line declaration and assignment
int width; //different line
width = 7;

See Also

Variables and types - C++ Tutorials

Add to Slack

< Write to File   |   Constants >

© 2019 SyntaxDB. All Rights Reserved.