Variable Declaration q Name of the memory location

Variable Declaration: q Name of the memory location is called variable. q. Variables are used to store the values that can be changed during the execution of a program. q. Before using any variable it must be required to declare first. q. Declaration of variable means required to specify data type , name of the variable followed by semicolon(; )

q. In C programming language , all variables must be required to declare at the top of the program , after opening the body , before writing the first statement. q. In Variable declaration name of the variable must be required to starts with alphabet (or) underscore ( _ ) only. q. In Declaration of variable , maximum length of variable name is 32 -characters only , after 32 character compiler will not consider remaining characters

• In declaration of the variable existing keywords , operators , separators , and constants values are not allowed. • SYNTAX FOR DECLARING VARIABLE [ Data_Type Variable. Name ; ] For eg: - int a; float sal; char a;

Data_type variable 1, variable 2, variable 3; eg: - int sal 1, sal 2, sal 3; • According to the syntax at least single space must be required between data type and name of the variable. • When we are declaring multiple variables of same data type then we required to use ( , ) as a separator.

• Some of the Examples on declaring of variables. 1. 2. 3. 4. 5. inta; (Error) int a; (Valid) int a b c d; (Error) int a, b, c, d; (Valid)

6. int abc, d; (valid) 7. int if; (Error) 8. int If; (Valid) 9. int _if; (Valid) 10. int 1 a, 1 b, 1 c, 2 a; (Error) .

int a 1, a 2, a 3, b 1; . (Valid) 12. int _1, _2, _3; (Valid) 13. int 1, 2, 3; (Error) 14. int total_salary; (valid) 15. int total-sal; (Error) 11.

Difference between Declaration and Initialization of a variable. -> In declaration of Variable , after creating the memory , it stores the garbage value by default until we are assigning the value. -> In Initialization of the variable , after creating the memory it stores the default value what we assigned. Declaration Initialization int a; a=10; int a=10; Gr 10 10
- Slides: 8