Variables

Local Variables in C

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


Syntax
dataType variableName;

Notes

dataType can be a primitive data type, or a user-defined data type (type definition).

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.


Example
int length = 5; //same line declaration and assignment

int width; //different line
width = 7;

See Also
Related

Type Definition

Documentation

GNU C Manual - Primitive Types

Add to Slack

< Including Header Files   |   Constants >

© 2019 SyntaxDB. All Rights Reserved.