C Tutorial Variables
Introduction to C language
Integer types
Char constants
Int constants
Type combination and promotion
Int overflow
Floating point types
Comments
Variables
Assignment operator
Truncation
Int vs float arithmatic
Mathematical operators
Unary Increment Operators
Pre and Post Variations
C Programming Cleverness and Ego Issues
Relational Operators
Logical Operators
Bitwise Operators
Other Assignment Operators

 

 
 
 
 

 

HOME
 

Variables

As in most languages, a variable declaration reserves and names an area in memory at run

time to hold a value of particular type. Syntactically, C puts the type first followed by the

name of the variable. The following declares an int variable named "num" and the 2nd line stores the value 42 into num.

 

int num;

num = 42;

 

 

num    42

 

A variable corresponds to an area of memory which can store a value of the given type. Making a drawing is an excellent way to think about the variables in a program. Draw each variable as box with the current value inside the box. This may seem like a

"beginner" technique, but when I'm buried in some horribly complex programming problem, I invariably resort to making a drawing to help think the problem through.

 

Variables, such as num, do not have their memory cleared or set in any way when they are allocated at run time. Variables start with random values, and it is up to the program

to set them to something sensible before depending on their values.

 

Names in C are case sensitive so "x" and "X" refer to different variables. Names can

contain digits and underscores (_), but may not begin with a digit. Multiple variables can

be declared after the type by separating them with commas. C is a classical "compile

time" language -- the names of the variables, their types, and their implementations are all

flushed out by the compiler at compile time (as opposed to figuring such details out at run

time like an interpreter).

 

float x, y, z, X;

 

Want more information and Video ???