From the course: C Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Defining variables

Defining variables - C Tutorial

From the course: C Essential Training

Defining variables

- Variables are strongly typed in C , and in C, that means that the token representing a variable represents both its value and its type. This is variable.cpp from chapter two of the exercise files. We come down here to line 10, you'll notice this 'int i' and a pair of curly braces and a semicolon. So that's a statement. And this statement is a variable definition. This defines a variable. It defines the name and the type of the variable, and it allocates space of a size sufficient to hold a value of that type. In other words, this is a variable of type integer, because it has this 'int' that's the type integer and its name is 'i'. And so there's a space allocated with enough space to hold an integer, and it's named 'i' in the symbol table. And here we have these curly braces, the empty curly braces initializes the variable by giving it an initial value of zero. Without initialization, if I take those curly…

Contents