SlideShare a Scribd company logo
C++
Numbers and
Strings
RAI MASAMUNE
Adding Numbers and Strings
If you add two numbers, the result will be a
number:
If you add two numbers, the result will be
a number:
If you add two strings, the result
will be a string concatenation:
If you try to add a number to a
string, an error occurs:
C++ String Length
String Length
To get the length of a string, use the length() function:
Tip: You might see some C++ programs that use the size() function to get the length of a string.
This is just an alias of length(). It is completely up to you if you want to use length() or size():
C++ Access Strings
Access Strings
You can access the characters in a string by referring to its index number inside
square brackets [].
This example prints the first character in myString:
Access String
Note: String indexes start with 0: [0] is the first character. [1] is the second
character, etc.
This example prints the second character in myString:
Change String Characters
To change the value of a specific character in a string, refer to the index number,
and use single quotes:

More Related Content

Similar to C++ Numbers and Strings.pptx

C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYRajeshkumar Reddy
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
samdamfa
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
Umme habiba
 
CHAPTER-2.ppt
CHAPTER-2.pptCHAPTER-2.ppt
CHAPTER-2.ppt
Tekle12
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
C# Strings
C# StringsC# Strings
C# Strings
Hock Leng PUAH
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSAami Kakakhel
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
guptkashish
 
Getting started with C++
Getting started with C++Getting started with C++
Getting started with C++
Asirbachan Sutar
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
 
Strings.pptx
Strings.pptxStrings.pptx
Strings.pptx
Yagna15
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
ishorishore
 
Python Strings Format
Python Strings FormatPython Strings Format
Python Strings Format
Mr Examples
 
Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptx
hardii0991
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 

Similar to C++ Numbers and Strings.pptx (20)

C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
Ch02
Ch02Ch02
Ch02
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
 
Compiler lab final report writing
Compiler lab final report writingCompiler lab final report writing
Compiler lab final report writing
 
CHAPTER-2.ppt
CHAPTER-2.pptCHAPTER-2.ppt
CHAPTER-2.ppt
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
C# Strings
C# StringsC# Strings
C# Strings
 
C++ PROGRAMMING BASICS
C++ PROGRAMMING BASICSC++ PROGRAMMING BASICS
C++ PROGRAMMING BASICS
 
Basic of c &c++
Basic of c &c++Basic of c &c++
Basic of c &c++
 
Savitch Ch 08
Savitch Ch 08Savitch Ch 08
Savitch Ch 08
 
Getting started with C++
Getting started with C++Getting started with C++
Getting started with C++
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
M C6java7
M C6java7M C6java7
M C6java7
 
Strings.pptx
Strings.pptxStrings.pptx
Strings.pptx
 
java or oops class not in kerala polytechnic 4rth semester nots j
java or oops class not in kerala polytechnic  4rth semester nots jjava or oops class not in kerala polytechnic  4rth semester nots j
java or oops class not in kerala polytechnic 4rth semester nots j
 
Python Strings Format
Python Strings FormatPython Strings Format
Python Strings Format
 
Cp module 2
Cp module 2Cp module 2
Cp module 2
 
Engineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptxEngineering CS 5th Sem Python Module -2.pptx
Engineering CS 5th Sem Python Module -2.pptx
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 

More from Rye Raine

Top-5-Quiz-Easy.pptx
Top-5-Quiz-Easy.pptxTop-5-Quiz-Easy.pptx
Top-5-Quiz-Easy.pptx
Rye Raine
 
Understanding IP Addresses.pptx
Understanding IP Addresses.pptxUnderstanding IP Addresses.pptx
Understanding IP Addresses.pptx
Rye Raine
 
AI Tools.pptx
AI Tools.pptxAI Tools.pptx
AI Tools.pptx
Rye Raine
 
Computer System Unit.pptx
Computer System Unit.pptxComputer System Unit.pptx
Computer System Unit.pptx
Rye Raine
 
What Does System Unit Mean.pptx
What Does System Unit Mean.pptxWhat Does System Unit Mean.pptx
What Does System Unit Mean.pptx
Rye Raine
 
Internet and Static.pptx
Internet and Static.pptxInternet and Static.pptx
Internet and Static.pptx
Rye Raine
 
Different types of Computer Network.pptx
Different types of Computer Network.pptxDifferent types of Computer Network.pptx
Different types of Computer Network.pptx
Rye Raine
 
Gamification.pptx
Gamification.pptxGamification.pptx
Gamification.pptx
Rye Raine
 
C++ Special Characters.pptx
C++ Special Characters.pptxC++ Special Characters.pptx
C++ Special Characters.pptx
Rye Raine
 
C++ User Input String.pptx
C++ User Input String.pptxC++ User Input String.pptx
C++ User Input String.pptx
Rye Raine
 
C++ Math.pptx
C++ Math.pptxC++ Math.pptx
C++ Math.pptx
Rye Raine
 
PECS.pptx
PECS.pptxPECS.pptx
PECS.pptx
Rye Raine
 
DIGITAL REPRESENTATION.pptx
DIGITAL REPRESENTATION.pptxDIGITAL REPRESENTATION.pptx
DIGITAL REPRESENTATION.pptx
Rye Raine
 
10 Excel skills to help you
10 Excel skills to help you 10 Excel skills to help you
10 Excel skills to help you
Rye Raine
 
Input Output and Part of Computer Desktop.pptx
Input Output and Part of Computer Desktop.pptxInput Output and Part of Computer Desktop.pptx
Input Output and Part of Computer Desktop.pptx
Rye Raine
 
Occupational Health and Safety Procedures 2022
Occupational Health and Safety Procedures 2022Occupational Health and Safety Procedures 2022
Occupational Health and Safety Procedures 2022
Rye Raine
 
Learning activity-sheet-module1 CSS 1.0
Learning activity-sheet-module1 CSS 1.0Learning activity-sheet-module1 CSS 1.0
Learning activity-sheet-module1 CSS 1.0
Rye Raine
 

More from Rye Raine (17)

Top-5-Quiz-Easy.pptx
Top-5-Quiz-Easy.pptxTop-5-Quiz-Easy.pptx
Top-5-Quiz-Easy.pptx
 
Understanding IP Addresses.pptx
Understanding IP Addresses.pptxUnderstanding IP Addresses.pptx
Understanding IP Addresses.pptx
 
AI Tools.pptx
AI Tools.pptxAI Tools.pptx
AI Tools.pptx
 
Computer System Unit.pptx
Computer System Unit.pptxComputer System Unit.pptx
Computer System Unit.pptx
 
What Does System Unit Mean.pptx
What Does System Unit Mean.pptxWhat Does System Unit Mean.pptx
What Does System Unit Mean.pptx
 
Internet and Static.pptx
Internet and Static.pptxInternet and Static.pptx
Internet and Static.pptx
 
Different types of Computer Network.pptx
Different types of Computer Network.pptxDifferent types of Computer Network.pptx
Different types of Computer Network.pptx
 
Gamification.pptx
Gamification.pptxGamification.pptx
Gamification.pptx
 
C++ Special Characters.pptx
C++ Special Characters.pptxC++ Special Characters.pptx
C++ Special Characters.pptx
 
C++ User Input String.pptx
C++ User Input String.pptxC++ User Input String.pptx
C++ User Input String.pptx
 
C++ Math.pptx
C++ Math.pptxC++ Math.pptx
C++ Math.pptx
 
PECS.pptx
PECS.pptxPECS.pptx
PECS.pptx
 
DIGITAL REPRESENTATION.pptx
DIGITAL REPRESENTATION.pptxDIGITAL REPRESENTATION.pptx
DIGITAL REPRESENTATION.pptx
 
10 Excel skills to help you
10 Excel skills to help you 10 Excel skills to help you
10 Excel skills to help you
 
Input Output and Part of Computer Desktop.pptx
Input Output and Part of Computer Desktop.pptxInput Output and Part of Computer Desktop.pptx
Input Output and Part of Computer Desktop.pptx
 
Occupational Health and Safety Procedures 2022
Occupational Health and Safety Procedures 2022Occupational Health and Safety Procedures 2022
Occupational Health and Safety Procedures 2022
 
Learning activity-sheet-module1 CSS 1.0
Learning activity-sheet-module1 CSS 1.0Learning activity-sheet-module1 CSS 1.0
Learning activity-sheet-module1 CSS 1.0
 

Recently uploaded

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

C++ Numbers and Strings.pptx

  • 2. Adding Numbers and Strings If you add two numbers, the result will be a number:
  • 3. If you add two numbers, the result will be a number:
  • 4. If you add two strings, the result will be a string concatenation:
  • 5. If you try to add a number to a string, an error occurs:
  • 6. C++ String Length String Length To get the length of a string, use the length() function: Tip: You might see some C++ programs that use the size() function to get the length of a string. This is just an alias of length(). It is completely up to you if you want to use length() or size():
  • 7. C++ Access Strings Access Strings You can access the characters in a string by referring to its index number inside square brackets []. This example prints the first character in myString:
  • 8. Access String Note: String indexes start with 0: [0] is the first character. [1] is the second character, etc. This example prints the second character in myString:
  • 9. Change String Characters To change the value of a specific character in a string, refer to the index number, and use single quotes: