Sunday, April 10, 2011

C constants and variables

A constant in C is a entity which never changes its value during the program execuation, whereas variables in C and C++ change their values during program execution. Examples of constants are numerals like 5,10, or 15 and there can be character constant also in C and C++ like 'a' or 'b'. These constant require some name to be associated with them so they can be used in computations. If we want to add 5 and 10 we can do so by using the expression like 5+10, but there is another way to do so with the help of variables. Before using a variable it should be declared. Variable declaration statement in C and C++ inlcudes the datatype and the name of variable like following:

Int number
char alphabet
Here number is a variable of type Integer which can hold integer values. In the same way alphabet is a variable of type Char which can hold Character values.

No comments:

Post a Comment