Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Constant and its types

Each language has a basic set of alphabets (character set). Similarly in C language we have a character set
that includes;
 Alphabets (A,B,C,……Z) , (a,b,c…….z)
 Digits (0-9)
 Special symbols (!, @, #, %, &, ( ), ; etc
These alphabets, digits, and special character symbol when combined in a specific manner form constant,
variables and keywords.
Constants: the values that cannot b changed by a program during execution e.g, 5,3,1800,40.5
In C language there are three types of constant
1)Integer constant 2)real constant 3)character constant
Integer constant: These are the value without decimal point. 301 -68 36 -745
Real constant: these are the value including decimal point. 2.5 70.0 -72.8
Character constant: any single lower and upper case letter. Digit, punctuation, special symbol enclosed
within “ ” is a character. For example ‘5’ “#” ‘z’ “3.7’ ‘/’
Note: ‘5’ is a different from 5
We can add two integers constant but cannot add two characters constant.
Activity : identify the type of constant
26 -45.3
6.4 7.00
‘k’ ‘-‘
65.10 0.88
‘*’ ‘A’
-80 36.367
Variables and its types
A variable is a name given to a memory location as the data is physically stored in the computer memory.
The value of a variable can be changed in a program during execution.
1 5 3 7 9 5
Each variable has a unique name called identifier and has a data type.
Data type: it describes the type of data that can be stored in a variable.
Data types
Types Data in C language Values
Integer int 520
Real float 45.7
Character char ‘a’
Data types of variable: it describes the not only the type of data but also the number of bytes that
compiler needs to reserve for data storage.
Integer- int” it is used to store integer value (whole number)
Integer takes 4 bytes of memory (some compiler use 2 bytes of memory)
Signed integer: it can save both positive and negative value.
Unsigned integer: it can save only positive value.
Floating point: it is used to store a real number up to 6 digits of precision.
It uses 4 bytes of memory.
Character –char: it can store one character only. It takes up just 1byte of memory for storage.

int a=7 ;
7 Reserved memory location

Variable name, its declaration and initialization


Rules for naming a variable
 A variable name can only contain alphabets (upper and lower case) digits and underscore sign.
 Variable name must begin with a digit.
 A reserved word ca n not used as a variable name.
 We should choose concise length for variable name.
Activity : Encircle valid variable name
_Hello 1var Roll-num Air55blue float
Case &car Name =color Float

Variable Declaration: Its mean specifying variable’s data type and giving it a valid name.
Syntax: data type variable name;
unsigned int age; float weight;
int salary; char gender;
Multiple variables of same data types may also be declared in a single statement.
unsigned int age, salary;
float height, weight;
Variable name cannot be declared without its data type after declaring a variable its data type cannot be
changed.
Void main ( )
{
Char grade;
int value;
}
Variable initialization: Assigning value to a variable for the first time.
C language allows us to initialize a variable both at the time of declaration and after declaring it.
Syntax : data.type varable name= value;
Example code
Void main ( )
{
int value= 97;
char grade;
grade=’A’
}
Activity: write a program that declares variables of a appropriate data type to store your personal data
initialize these variables with following data.

 Initialize letter of your name


 Initialize letter of your gender
 Your age
 Your marks in 9th class
 Your height
Q: write a program that declares variable of data types to store your friend personal data and initialize
these variables.
Initialize letter of name Initialize letter of gender
Age marks in 9th class height
Q: Rewrite the following code after removing error
@inculde(stdio.)
Void main{}
Int m;
67=m:
]
Q: write any three rules for declaring variable. Q: list any 5 data types in C.
Q: what is difference b/w signed and un signed int? Q:Give any 10 example of valid variable name.

Q: write a program that declares variable of data types to store your friend personal data and initialize
these variables.
Initialize letter of name Initialize letter of gender
th
Age marks in 9 class height
Q: Rewrite the following code after removing error
@inculde(stdio.)
Void main{}
Int m;
67=m:
]
Q: write any three rules for declaring variable. Q: list any 5 data types in C.
Q: what is difference b/w signed and un signed int? Q:Give any 10 example of valid variable name.

Q: write a program that declares variable of data types to store your friend personal data and initialize
these variables.
Initialize letter of name Initialize letter of gender
Age marks in 9th class height
Q: Rewrite the following code after removing error
@inculde(stdio.)
Void main{}
Int m;
67=m:
]
Q: write any three rules for declaring variable. Q: list any 5 data types in C.
Q: what is difference b/w signed and un signed int? Q:Give any 10 example of valid variable name.
Q:What is programming language? (3)
Q: Define IDE with example. (5)
Q: What is syntax? Explain syntax error. (5)
Q: Explain compiler (3)
Q:what are reserve words. write a list of reserve words. (4)

Q:What is programming language? (3)


Q: Define IDE with example. (5)
Q: What is syntax? Explain syntax error. (5)
Q: Explain compiler (3)
Q:what are reserve words. write a list of reserve words. (4)

Q:What is programming language? (3)


Q: Define IDE with example. (5)
Q: What is syntax? Explain syntax error. (5)
Q: Explain compiler (3)
Q:what are reserve words. write a list of reserve words. (4)

Q:What is programming language? (3)


Q: Define IDE with example. (5)
Q: What is syntax? Explain syntax error. (5)
Q: Explain compiler (3)
Q:what are reserve words. write a list of reserve words. (4)

Q:What is programming language? (3)


Q: Define IDE with example. (5)
Q: What is syntax? Explain syntax error. (5)
Q: Explain compiler (3)
Q:what are reserve words. write a list of reserve words. (4)

Q:What is programming language? (3)


Q: Define IDE with example. (5)
Q: What is syntax? Explain syntax error. (5)
Q: Explain compiler (3)
Q:what are reserve words. write a list of reserve words. (4)

You might also like