SlideShare a Scribd company logo
1 of 18
Download to read offline
Introduction to C++
VARIABLES ,DATA TYPES
AND CONSTANTS
Variables
 A variable is a memory location that is used to store
values .
 To understand what this means let us take an
example.
 Consider the memory of the computer to contain of
equal sized cells capable of storing data.
 These cells have unique addresses. Since we store
data in these we need to refer to them in our program.
 It is humanly impossible to remember all the
addresses
Memory locations having unique memory addresses
So We can name these Memory locations with some user defined names(identifier) like
we have named this one as age.
Here age is the name given to memory location AFXX011 and is called the variable age.
We shall see how to declare a variable discussing data types
age
How do we use Variables ?
 In order to be able to use the memory location as a
variable we need to declare it ie allocate memory to it.
 A variable can be declared using a data type and a
valid identifier.
 Let us first discuss data types.
What is a Data Type?
A data type defines a set of values
and the operations that can be
performed on that data.
Data Operations Data Type
Why do we need a data
type?
 As all of you must be aware that a computer is just a machine. It cannot
by itself distinguish between various types of Data. This means that it
cannot distinguish between the number 20 and the letter ‘A’ or the word
“good” . For the computer all of this is just a piece of data.
 It is the programmer who must tell the computer that 20 is a number, ‘A’
is a character and ‘good’ is a word. How do we do it?
 By using data types we can classify the different data for the computer
so that it can be stored and processed in a certain manner.
C++ Data Types : Categories
C++ Data
Types
In-Built
int, char,
float, void
User
Defined
Classes ,
structures
Derived
Arrays
The C++ data types can be categorized as
C++ Data Types: In-built
 C++ supports four basic data types :
Basic Data
types
int char float void
void
The void type has no values and no
operations. In other words, both the set
of values and the set of operations are
empty. Although this might seem unusual,
we will see later that it is a very
useful data type.
Characteristics of data types
 All data types have a certain size associated with
them. This essentially means that data of each type
has to be stored in a certain no of bytes.
 Each data type has a range of permissible values
associated with it which is also its domain.
 All data type have some modifiers to accommodate
various ranges for eg int data type has short long
int data type
Variables declared as integers are capable of storing whole numbers These
are numbers without decimal point.
There are three variants of integer type. These differ in size. The following is
a table showing the size and domain of integer data types.
Type modifier Size
(byte
s)
Min value Max value Sample data
(To Store)
short
int
Signed
Unsigned
2 -32768
0
32767
65535
Marks
Age
int signed
unsigned
2 -32768
0
32767
65535
long
int
signed
unsigned
4 -2,147,483,648
0
2,147,483,647
4,294,967,295
Population
Floating Point
A floating-point variable is capable of storing
a number with a fractional part. The C++
language supports three different sizes of
floating-point: float, double and long double.
Type Size
(byt
es)
Min value Max value Sample
data
(To Store)
float 4 3.4 E -38 3.4 E 38 Average
double 6 1.7 E -308 1.7 E 308 Huge
fractional
calculation
Long
double
10 3.4 E -4932 3.4 E 4932 Stellar
distances
Char data type
A char variable is capable of storing any
character on the keyboard. The ASCII code of
the character is stored.eg the symbol ‘+’, the
letter ‘A’ etc.
Type Size
(byt
es)
Domain Sample
data
(To Store)
char 1 Any character on the keyboard Symbol
operator
Variable declarations
A variable declaration specifies the type and the name of the
variable.
A variable has a type and it can contain only values of that type.
For example, a variable of the type int can only hold
integer values.
Syntax:
data type identifier ; //declaration
data type identifier = value; // initialization
Examples:
int age;
int no_of_books = 45;
char letter= 'y';
double price = 2493.14;
float temp = -24.5;
Variable declarations
 When initializing a constant or a variable of char type,
or when changing the value of a variable of char type,
the value is enclosed in single quotation marks.
Examples:
const char star = '*';
char letter = ‘D';
Declaration vs Initialization
 When a variable is given a value at the time of
declaration itself this is known as initialization
int num;
int num=89
 Variables are not automatically initialized. For
example, after declaration
int sum;
the value of the variable sum can be anything
(garbage).
 Thus, it is good practice to initialize variables when
they are declared.
Constant declarations
 Constants are used to store values that never change
during the program execution.
 Using constants makes programs more readable and
maintainable.
Syntax:
const data type identifier = value;
Examples:
const double rate = 7.8;
const int x= 45;

More Related Content

Similar to variablesfinal-170820055428 data type results

Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Typesk v
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfYRABHI
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programmingHarshita Yadav
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introductionnikshaikh786
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingSherwin Banaag Sapin
 
datatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxdatatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxNaniBhai3
 
What are variables and keywords in c++
What are variables and keywords in c++What are variables and keywords in c++
What are variables and keywords in c++Abdul Hafeez
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6REHAN IJAZ
 
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxAmrutaNavale2
 
02 Primitive data types and variables
02 Primitive data types and variables02 Primitive data types and variables
02 Primitive data types and variablesmaznabili
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptxjamilmalik19
 
Data Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docxData Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docxtheodorelove43763
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structsSaad Sheikh
 

Similar to variablesfinal-170820055428 data type results (20)

Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
cassignmentii-170424105623.pdf
cassignmentii-170424105623.pdfcassignmentii-170424105623.pdf
cassignmentii-170424105623.pdf
 
data types in C programming
data types in C programmingdata types in C programming
data types in C programming
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
Data type
Data typeData type
Data type
 
C tokens
C tokensC tokens
C tokens
 
datatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxdatatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptx
 
What are variables and keywords in c++
What are variables and keywords in c++What are variables and keywords in c++
What are variables and keywords in c++
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
 
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
 
02 Primitive data types and variables
02 Primitive data types and variables02 Primitive data types and variables
02 Primitive data types and variables
 
Data types
Data typesData types
Data types
 
Data Types and variables in C++.pptx
Data Types and variables in C++.pptxData Types and variables in C++.pptx
Data Types and variables in C++.pptx
 
Data Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docxData Type is a basic classification which identifies.docx
Data Type is a basic classification which identifies.docx
 
C data types, arrays and structs
C data types, arrays and structsC data types, arrays and structs
C data types, arrays and structs
 
Data type
Data typeData type
Data type
 

Recently uploaded

Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...narwatsonia7
 
Call Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls Service
Call Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls ServiceCall Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls Service
Call Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls Servicenarwatsonia7
 
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...Miss joya
 
Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service CoimbatoreCall Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatorenarwatsonia7
 
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls ServiceCALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls ServiceMiss joya
 
CALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune) Girls Service
CALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune)  Girls ServiceCALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune)  Girls Service
CALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune) Girls ServiceMiss joya
 
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.MiadAlsulami
 
Kesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls Service
Kesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls ServiceKesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls Service
Kesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls Servicemakika9823
 
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...Garima Khatri
 
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy GirlsCall Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girlsnehamumbai
 
Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...
Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...
Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...Call girls in Ahmedabad High profile
 
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...astropune
 
VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...
VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...
VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...Miss joya
 
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...narwatsonia7
 
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Deliverynehamumbai
 
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...astropune
 
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...Miss joya
 
Aspirin presentation slides by Dr. Rewas Ali
Aspirin presentation slides by Dr. Rewas AliAspirin presentation slides by Dr. Rewas Ali
Aspirin presentation slides by Dr. Rewas AliRewAs ALI
 
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...Miss joya
 

Recently uploaded (20)

Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
 
Call Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls Service
Call Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls ServiceCall Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls Service
Call Girls Service Bellary Road Just Call 7001305949 Enjoy College Girls Service
 
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
Russian Call Girls in Pune Riya 9907093804 Short 1500 Night 6000 Best call gi...
 
Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service CoimbatoreCall Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatore
 
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls ServiceCALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune)  Girls Service
CALL ON ➥9907093804 🔝 Call Girls Hadapsar ( Pune) Girls Service
 
CALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune) Girls Service
CALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune)  Girls ServiceCALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune)  Girls Service
CALL ON ➥9907093804 🔝 Call Girls Baramati ( Pune) Girls Service
 
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
 
Kesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls Service
Kesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls ServiceKesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls Service
Kesar Bagh Call Girl Price 9548273370 , Lucknow Call Girls Service
 
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
VIP Mumbai Call Girls Hiranandani Gardens Just Call 9920874524 with A/C Room ...
 
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy GirlsCall Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
 
Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...
Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...
Call Girls Service Navi Mumbai Samaira 8617697112 Independent Escort Service ...
 
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
 
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Servicesauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
 
VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...
VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...
VIP Call Girls Pune Vrinda 9907093804 Short 1500 Night 6000 Best call girls S...
 
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
 
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
 
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
 
Aspirin presentation slides by Dr. Rewas Ali
Aspirin presentation slides by Dr. Rewas AliAspirin presentation slides by Dr. Rewas Ali
Aspirin presentation slides by Dr. Rewas Ali
 
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
 

variablesfinal-170820055428 data type results

  • 1. Introduction to C++ VARIABLES ,DATA TYPES AND CONSTANTS
  • 2. Variables  A variable is a memory location that is used to store values .  To understand what this means let us take an example.  Consider the memory of the computer to contain of equal sized cells capable of storing data.  These cells have unique addresses. Since we store data in these we need to refer to them in our program.  It is humanly impossible to remember all the addresses
  • 3. Memory locations having unique memory addresses
  • 4. So We can name these Memory locations with some user defined names(identifier) like we have named this one as age. Here age is the name given to memory location AFXX011 and is called the variable age. We shall see how to declare a variable discussing data types age
  • 5. How do we use Variables ?  In order to be able to use the memory location as a variable we need to declare it ie allocate memory to it.  A variable can be declared using a data type and a valid identifier.  Let us first discuss data types.
  • 6. What is a Data Type? A data type defines a set of values and the operations that can be performed on that data. Data Operations Data Type
  • 7. Why do we need a data type?  As all of you must be aware that a computer is just a machine. It cannot by itself distinguish between various types of Data. This means that it cannot distinguish between the number 20 and the letter ‘A’ or the word “good” . For the computer all of this is just a piece of data.  It is the programmer who must tell the computer that 20 is a number, ‘A’ is a character and ‘good’ is a word. How do we do it?  By using data types we can classify the different data for the computer so that it can be stored and processed in a certain manner.
  • 8. C++ Data Types : Categories C++ Data Types In-Built int, char, float, void User Defined Classes , structures Derived Arrays The C++ data types can be categorized as
  • 9. C++ Data Types: In-built  C++ supports four basic data types : Basic Data types int char float void
  • 10. void The void type has no values and no operations. In other words, both the set of values and the set of operations are empty. Although this might seem unusual, we will see later that it is a very useful data type.
  • 11. Characteristics of data types  All data types have a certain size associated with them. This essentially means that data of each type has to be stored in a certain no of bytes.  Each data type has a range of permissible values associated with it which is also its domain.  All data type have some modifiers to accommodate various ranges for eg int data type has short long
  • 12. int data type Variables declared as integers are capable of storing whole numbers These are numbers without decimal point. There are three variants of integer type. These differ in size. The following is a table showing the size and domain of integer data types. Type modifier Size (byte s) Min value Max value Sample data (To Store) short int Signed Unsigned 2 -32768 0 32767 65535 Marks Age int signed unsigned 2 -32768 0 32767 65535 long int signed unsigned 4 -2,147,483,648 0 2,147,483,647 4,294,967,295 Population
  • 13. Floating Point A floating-point variable is capable of storing a number with a fractional part. The C++ language supports three different sizes of floating-point: float, double and long double. Type Size (byt es) Min value Max value Sample data (To Store) float 4 3.4 E -38 3.4 E 38 Average double 6 1.7 E -308 1.7 E 308 Huge fractional calculation Long double 10 3.4 E -4932 3.4 E 4932 Stellar distances
  • 14. Char data type A char variable is capable of storing any character on the keyboard. The ASCII code of the character is stored.eg the symbol ‘+’, the letter ‘A’ etc. Type Size (byt es) Domain Sample data (To Store) char 1 Any character on the keyboard Symbol operator
  • 15. Variable declarations A variable declaration specifies the type and the name of the variable. A variable has a type and it can contain only values of that type. For example, a variable of the type int can only hold integer values. Syntax: data type identifier ; //declaration data type identifier = value; // initialization Examples: int age; int no_of_books = 45; char letter= 'y'; double price = 2493.14; float temp = -24.5;
  • 16. Variable declarations  When initializing a constant or a variable of char type, or when changing the value of a variable of char type, the value is enclosed in single quotation marks. Examples: const char star = '*'; char letter = ‘D';
  • 17. Declaration vs Initialization  When a variable is given a value at the time of declaration itself this is known as initialization int num; int num=89  Variables are not automatically initialized. For example, after declaration int sum; the value of the variable sum can be anything (garbage).  Thus, it is good practice to initialize variables when they are declared.
  • 18. Constant declarations  Constants are used to store values that never change during the program execution.  Using constants makes programs more readable and maintainable. Syntax: const data type identifier = value; Examples: const double rate = 7.8; const int x= 45;