Showing posts with label variable declaration. Show all posts
Showing posts with label variable declaration. Show all posts

Friday, May 16, 2008

Variable declaration

Variable declaration

All the variables must be declared before their use. It does two things:

(a) Tell the compiler what the variable name is.

(b) Specify what type of data that a variable will hold.

Syntax of variable declaration:

data_type variable_name;

Example of variable declaration:
int i,j,k;
char ch;

Assigning values to variables

Assigning values to variables

To assign values to the variables, assignment operator (=) is used.

Syntax of assigning values:

variable declaration;
Variable_name = value;

Example of assigning values:

Int i , j;
j = 5 ;
i = 0 ;

It is also possible to assign a value at the time of declaration.
e.g.
int i = 5;

More than one variable can be initialized in one statement using multiple assignment operators.

e.g. j = m = 2;

There could be an exception while using multiple assignment operators.

e.g. int i , j = 2 , k;

here the assignment will be i = 0 j=2 and k = garbage value

Copyright

Copyright © 2008 C Tutorial, All rights are reserved