SlideShare una empresa de Scribd logo
1 de 10
VARIABLES AND DATA TYPES
IICT – Lab-8 IN C++
VARIABLE
• Portion of Memory to Store a Value.
• Each variable needs a unique name that distinguishes it from
others.
• Name of the variable should be a valid C++ Identifier.
a=5;
b=2;
In this, variable names are ‘a’ and ‘b’
VARIABLE
Memory
5
a=5;
a
Memory Location reserved
And named as “a”
IDENTIFIERS
• A valid identifier is a sequence of one or more letters, digits or
underscore “ _ “
• A valid identifier shall always begin with a letter or underscore “ _ “
• A valid identifier CAN’T contain Spaces, punctuation marks or any
other symbols.
• A valid identifier CAN’T start with a digit in any case.
• A valid identifier CAN’T be a Reserved Keyword of C++
RESERVED KEYWORDS
Following are reserved keywords of C++ and can’t be used as
identifiers.
alignas, alignof, and, and_eq, asm, auto, bitand, bitor, bool, break,
case, catch, char, char16_t, char32_t, class, compl, const, constexpr,
const_cast, continue, decltype, default, delete, do, double,
dynamic_cast, else, enum, explicit, export, extern, false, float, for,
friend, goto, if, inline, int, long, mutable, namespace, new, noexcept,
not, not_eq, nullptr, operator, or, or_eq, private, protected, public,
register, reinterpret_cast, return, short, signed, sizeof, static,
static_assert, static_cast, struct, switch, template, this, thread_local,
throw, true, try, typedef, typeid, typename, union, unsigned, using,
virtual, void, volatile, wchar_t, while, xor, xor_eq
ARE THESE VALID IDENTIFIERS?
1. A
2. result
3. temppp
4. 6B
5. B46_34a
6. a.jok
7. 0_klm
8. _7ab
9. aaaa
10._a_b_







X
X
X
Result result RESULT resulT
C++ is a Case-Sensitive Language
and so are its Identifiers.
IDENTIFIERS
DATA TYPES
• Character [ char ]
• Integer [ int ]
• Float [ float ]
• Boolean [ bool ]
DECLARATION OF VARIABLES
• Identifier for variable, followed by its data type.
int a;
float mynumber;
• To declare more than one variables of same type, separate their
identifiers with commas, in single statement.
int a,b,c; int a;
int b;
int c;
(It is exactly same as declaring variables like this)
INITIALIZATION OF VARIABLES
• Assigning a value to the variable from the moment it is declared.
int a=5; (value of a is 5)
float mynumber=2.5; (value of mynumber is 2.5)
int b; (value of b is undertermined)

Más contenido relacionado

La actualidad más candente

Data types in C language
Data types in C languageData types in C language
Data types in C language
kashyap399
 

La actualidad más candente (20)

File in C language
File in C languageFile in C language
File in C language
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3Header files of c++ unit 3 -topic 3
Header files of c++ unit 3 -topic 3
 
C introduction by thooyavan
C introduction by  thooyavanC introduction by  thooyavan
C introduction by thooyavan
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Functions in C
Functions in CFunctions in C
Functions in C
 
C program
C programC program
C program
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
C++ string
C++ stringC++ string
C++ string
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Embedded C - Lecture 3
Embedded C - Lecture 3Embedded C - Lecture 3
Embedded C - Lecture 3
 

Destacado

Types of computer networks
Types of computer networksTypes of computer networks
Types of computer networks
Harsh Sachdev
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol28
 
types of computer networks, protocols and standards
types of computer networks, protocols and standardstypes of computer networks, protocols and standards
types of computer networks, protocols and standards
Midhun Menon
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
Vasavi College of Engg
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
Varun Garg
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 

Destacado (19)

A presentation on types of network
A presentation on types of networkA presentation on types of network
A presentation on types of network
 
Overloading of io stream operators
Overloading of io stream operatorsOverloading of io stream operators
Overloading of io stream operators
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Types of computer networks
Types of computer networksTypes of computer networks
Types of computer networks
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Overview of programming paradigms
Overview of programming paradigmsOverview of programming paradigms
Overview of programming paradigms
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Prgramming paradigms
Prgramming paradigmsPrgramming paradigms
Prgramming paradigms
 
Paradigms
ParadigmsParadigms
Paradigms
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
types of computer networks, protocols and standards
types of computer networks, protocols and standardstypes of computer networks, protocols and standards
types of computer networks, protocols and standards
 
Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming Paradigms
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Unit1 principle of programming language
Unit1 principle of programming languageUnit1 principle of programming language
Unit1 principle of programming language
 
Concept Of C++ Data Types
Concept Of C++ Data TypesConcept Of C++ Data Types
Concept Of C++ Data Types
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
Ppt of types of-network
Ppt of types of-network Ppt of types of-network
Ppt of types of-network
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 

Similar a Variables and data types in C++

FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
rohassanie
 
1.getting started with c
1.getting started with c1.getting started with c
1.getting started with c
Hardik gupta
 
Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1
patcha535
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
Murali M
 

Similar a Variables and data types in C++ (20)

Java chapter 2
Java chapter 2Java chapter 2
Java chapter 2
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Lec9
Lec9Lec9
Lec9
 
C language basics
C language basicsC language basics
C language basics
 
FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2FP 201 Unit 2 - Part 2
FP 201 Unit 2 - Part 2
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
1.getting started with c
1.getting started with c1.getting started with c
1.getting started with c
 
Chapter 13.1.1
Chapter 13.1.1Chapter 13.1.1
Chapter 13.1.1
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
 
Overview of c
Overview of cOverview of c
Overview of c
 
Computer programming - variables constants operators expressions and statements
Computer programming - variables constants operators expressions and statementsComputer programming - variables constants operators expressions and statements
Computer programming - variables constants operators expressions and statements
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
Lec 1.3 Object Oriented Programming
Lec 1.3 Object Oriented ProgrammingLec 1.3 Object Oriented Programming
Lec 1.3 Object Oriented Programming
 
Pi j1.2 variable-assignment
Pi j1.2 variable-assignmentPi j1.2 variable-assignment
Pi j1.2 variable-assignment
 
Data type
Data typeData type
Data type
 
C Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptxC Programming Lecture 3 - Elements of C.pptx
C Programming Lecture 3 - Elements of C.pptx
 
lec 2.pptx
lec 2.pptxlec 2.pptx
lec 2.pptx
 

Más de Ameer Khan (7)

Starting c++
Starting c++Starting c++
Starting c++
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
Role of motivation in language learning
Role of motivation in language learningRole of motivation in language learning
Role of motivation in language learning
 
Personality disorders (Psychology)
Personality disorders (Psychology)Personality disorders (Psychology)
Personality disorders (Psychology)
 
Self concept in ipc by Ameer Khan
Self concept in ipc by Ameer KhanSelf concept in ipc by Ameer Khan
Self concept in ipc by Ameer Khan
 
Self in IPC
Self in IPCSelf in IPC
Self in IPC
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Último (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

Variables and data types in C++

  • 1. VARIABLES AND DATA TYPES IICT – Lab-8 IN C++
  • 2. VARIABLE • Portion of Memory to Store a Value. • Each variable needs a unique name that distinguishes it from others. • Name of the variable should be a valid C++ Identifier. a=5; b=2; In this, variable names are ‘a’ and ‘b’
  • 4. IDENTIFIERS • A valid identifier is a sequence of one or more letters, digits or underscore “ _ “ • A valid identifier shall always begin with a letter or underscore “ _ “ • A valid identifier CAN’T contain Spaces, punctuation marks or any other symbols. • A valid identifier CAN’T start with a digit in any case. • A valid identifier CAN’T be a Reserved Keyword of C++
  • 5. RESERVED KEYWORDS Following are reserved keywords of C++ and can’t be used as identifiers. alignas, alignof, and, and_eq, asm, auto, bitand, bitor, bool, break, case, catch, char, char16_t, char32_t, class, compl, const, constexpr, const_cast, continue, decltype, default, delete, do, double, dynamic_cast, else, enum, explicit, export, extern, false, float, for, friend, goto, if, inline, int, long, mutable, namespace, new, noexcept, not, not_eq, nullptr, operator, or, or_eq, private, protected, public, register, reinterpret_cast, return, short, signed, sizeof, static, static_assert, static_cast, struct, switch, template, this, thread_local, throw, true, try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t, while, xor, xor_eq
  • 6. ARE THESE VALID IDENTIFIERS? 1. A 2. result 3. temppp 4. 6B 5. B46_34a 6. a.jok 7. 0_klm 8. _7ab 9. aaaa 10._a_b_        X X X
  • 7. Result result RESULT resulT C++ is a Case-Sensitive Language and so are its Identifiers. IDENTIFIERS
  • 8. DATA TYPES • Character [ char ] • Integer [ int ] • Float [ float ] • Boolean [ bool ]
  • 9. DECLARATION OF VARIABLES • Identifier for variable, followed by its data type. int a; float mynumber; • To declare more than one variables of same type, separate their identifiers with commas, in single statement. int a,b,c; int a; int b; int c; (It is exactly same as declaring variables like this)
  • 10. INITIALIZATION OF VARIABLES • Assigning a value to the variable from the moment it is declared. int a=5; (value of a is 5) float mynumber=2.5; (value of mynumber is 2.5) int b; (value of b is undertermined)