UNIT 2 2.3 Variables and Constant Declarations Flashcards
These are identifiers which can be assigned a value within a program.
It has 32 valid characters, and these are letters, digits, and underscore
Variables
Syntax:
for variable
Data-type ;
/* list of variables separated by commas.*/
Example int x, y, z; char a, b ; double s; float ave; char Sname[30];
The process of assigning starting values to the variables It is important to remember that
variables are not initialized automatically
Variables initialization
Several Ways to Initialize a Variables:
- By assigning an assignment statement (=)
ex:
x = -1;
Chl = ‘A’; - By using function scanf
ex:
scanf(“%d”, &x);
scanf(“%lf”, &y) ;
3. By assigning values during declaration: ex: int x =3; char y = ‘x’; double a, b = 100.00;
Variables that are initialized only at the start of the program. All of these variables are
initialized to zero if no other initializer is specified.
Global Variables
Variables that are initialized each time the function in which they are declared is
entered.
Local Variables