You are on page 1of 15

CAP 172

PROGRAMMING METHODOLOGIES

UNIT- 2
LECTURE - 3
POLL
Q. Identify the odd one out:

a)^
b)&
c)||
d)|
POLL
Q. Identify the odd one out:

a)&&
b)||
c)!
d)~
We will discuss:

 Constants

 Variables

 Data Types

 Polling Questions and Answers


Constants
The entity which do not change throughout the
execution are called constants.
Types of constants:
•Integer constant
•Character constant
•Floating point constants
•String constants
Name of person remains same through out
the life, example: Sapna, Abdul, etc.
Character Constants
Constants enclosed in single quotes(‘ ’).
It can be any letter from character set.

String Constants Example : ‘\n’, ‘\t’ or ‘a’

Set of zero or more characters enclosed in double


quotes (eg: “ ” )
It is represented as sequence of characters within
double quotes.

Example : “This is C programming”


Integer Constants
When the constant contains only digits without
any decimal part
Example : 5; -987;

Floating Point Constants


Constants that contains number with decimal
points
Example : 3.14; 309.89
Constants
Variables
• Variable is an entity which may change.
• Variable is used to hold result and reserve
memory for the data.
Syntax: datatype variable_name;
• The naming of variable is done by following the
same rules of identifier naming.

Eg. What is your hobby?


The answer could be reading, dancing, drawing, etc.
So the answer to such questions may change during the life time of the person
Data Types in C
• Why Data types?
• C language has some predefined set of data types to handle
various kinds of data that we use in our program.
• These data types have different storage capacities.
• Primary Data Type: integer(int), floating(float),
character(char) and void.
• Derived Data Type: arrays, functions, structures and pointers.
Integer Type
Floating Point Type
Character Type
POLL
Q. What is the problem in following variable declaration?
3Bedroom-Hall-Kitchen?;

a) The variable name begins with an integer


b) The special character ‘-‘
c) The special character ‘?’
d) All of the mentioned

You might also like