What is a Variable in C Language? | Variable Declaration and initialization.pptx

Shafqatali06 350 views 6 slides Jan 18, 2024
Slide 1
Slide 1 of 6
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6

About This Presentation

Here you will find What is a variable in C language, Variable Definition, Variable Declaration, Variable Initialization and Rules for naming a variable in C Language


Slide Content

What is a Variable? In Mathematics , A variable is some letter which hold some value, Like x=20 . A variable’s value will vary(change) accordingly. Variables are used in expressions and equations .

What is a Variable? In Programming , A variable is a named memory location which holds input data and its computational results. E.g. marks = 97 . It is same like a box that you label and put some stuff into.

Characteristics of a Variable? Variables are created in RAM, So data stored in Variables is temporary Variable Declaration Writing variable name with its data type is called Variable declaration. It tells the compiler the name of the variable to be used in program and type of information to be stored in it Syntax: Data Type Variable Name; Example: int marks; float height; char x; int x,y,z,a,age; C is a strongly typed language, so all variables must be declared before being used. The compiler will report error if an undeclared variable is used in a program.

Variable Initialization Assigning a value first time after Variable declaration is called variable initialization Syntax: Data Type Variable Name = value; Example: int marks = 99; float height; height = 170;

Rules fo r for naming a variable Variable name in C consists of letters, numbers, or an underscore. First character of a variable should be a letter or underscore(_). Keywords can not be used for variable names like int, void etc. Blank space between variable names is not allowed.

Constant A constant is an identifier whose value cannot be changed during program execution. E.g. PI