Lecture 6 Data Types and Variables
Lecture 6 Data Types and Variables
2
Problem solving
with
programming
Course Outcome
CO Title Level
Number
CO1 Identifysituations where computational Understand
methods would be useful.
Sr. Type of Assessment Weightage of actual Frequency of Task Final Weightage in Internal Remarks
No. Task conduct Assessment (Prorated
Marks)
5
Data
Data Types types
Data type is used to specify the range of values that a
particular variable can take during program execution
6
Data
Data Types- types
Categories
Primary Data Types: These data types are predefined into C system
Their storage space , range of values and format specifiers are all fixed
Derived Data Types : The data types which are derived from primary
data types are called derived data types .
User Defined Data Types : These data type are defined by users
according to their requirements with the combination of primary data
types .
7
Data types
8
Data types Size Chart
9
Data types Size Chart
Data Type Memory Space Range Of Values Format Specifiers
-9223372036854775808
signed long long int 8 Bytes To %lld
9223372036854775807
0
unsigned long long int 8 Bytes To %llu
18446744073709551615
-3.4 E38
float 4 Bytes To %f
+3.4E38
-1.7E308
double 8 Bytes To %lf
+1.7E308
10
Data types
Steps to remember
1.The formula to calculate range is -2n-1 To 2n-1-1 where n is the no. of bits taken by a
particular data type.
3. The Ranges of data types are specified here according to 16-bit compiler .
4. Ranges for int and long data types are compiler dependent that will vary from 16 bit
compiler to 64 bit compiler .
11
Constants
Constants
12
Integer Constant
Integer Constants
13
Real Constant
Real Constants
14
Character Constant
Character Constants
These constants are represented in ‘ ‘ as ‘a’ . Special characters are
used in C language that are preceded by \ like ‘\t’ and ‘\n’ are
characters which are used as tab and new line Characters
characters in C
‘a’ // valid character constant
‘5’ // digit can be represented in char form
‘&’ // special symbol can be represented as character constant
‘\t’ // Special Character represents tab
‘an’ // Invalid it should include only single char
15
String
StringConstant
Constants
16
How to Define Constants ?
17
How to Define Constants ?
18
Variables
Variables
Variables are the quantities whose value changes during the execution
of the program Variable name is always preceded with some valid data
type that fixes the memory space for the variable to store it .
Actually variable is the name given to memory location whose value
can be manipulated according to the program requirements .
example : int a=5;
a is the variable of type integer in which initial value as 5 is placed
19
Naming The Variables
The variable name may include alphabets , digits or underscore .The name of the
variable is also known as identifier .
Following are the rules for naming the variables
1.Any keyword cannot be used for naming the variable
int break; // Invalid identifier as break is a keyword in C .
2.Space is not allowed in a variable name
int a b // space is not allowed in a variable name .
20
Lva Rvalue
Lvalue
lvalue − Expressions that may appear on L.H.S as well as on R.H.S of
the assignment operator
rvalue – it is the expression that evaluated to constant value and can
appear only on the R.H.S of the assignment operator .
Example :
int a,b;
b=10; // Valid as rvalue constant 10 is on R.H.S of =
10=a; // Invalid as rvalue 10 is on L.H.S of =
a=b; // Valid as both are variables may appear on either side of =
21
Summary
Are used to declare variables .It specifies range , format specifier
Data types
and memory space required by corresponding variable
Constants Are quantities that do not change its value during program
execution.
23
Q7: What are the memory space requirements
of derived data types ?
Q5: Can we change value of constant defined by
#define ? Ans: Derived data types are the combination of
predefined data types so their space is
Ans: No, Constant of any type cannot be calculated by adding up space of all primary
modified data types from which derived data type
composed of .
FAQs
Q6: I store my city population in int variable it Q8 : When I use short x; compiler did not
is 50000 but when I print it was some garbage generate any error message.Ccan we use short
value why it happened ? without int ?
Ans: You worked on 16 bit compiler. int take Ans: short x; or short int x ; have same meaning
two bytes and can store value in range -32768 so compiler will not generate any error
to 32767 so 50000 cannot be stored in this message .
variable you can take long to store this value .
24
Test Yourself
25
References
S.No Title Content link
1 Book Programming in C by Reema Thareja.
2 Book Programming with C (Schaum's Outline Series) by Byron
Gottfried Jitender Chhabra, Tata McGraw Hill.
3 Book The C Programming Language by Brian W. Kernighan, Dennis
Ritchie, Pearson education.
4 Book Programming in ANSI C by E. Balaguruswamy, Tata McGraw
Hill.
5 Weblink https://www.tutorialspoint.com/cprogramming/c_operators.htm
6 Weblink https://www.programiz.com/c-programming
7 Weblink https://fresh2refresh.com/c-programming/
References
S.No Title Content link
8 Weblink https://www.studytonight.com/c/
9 Weblink https://www.javatpoint.com/c-operators
10 Video Link https://www.youtube.com/watch?v=OSyjOvFbAGI
11 Video Link https://www.youtube.com/watch?v=d7tdL-ZEWdE