SlideShare ist ein Scribd-Unternehmen logo
1 von 4
CPlusPlus arrays and strings
Mr. A / 1 day ago
image credit:http://wiki.codeblocks.org
CPlusPlus arrays and strings
CPlusPlus arrays and strings provide greater flexibility to store similar categories or types of
values like integers, characters, decimals or even strings(to be discussed later)
When we were using the variables in our previous post, what we were concluding was:
A variable hold single value of certain type(s). With the facility of arrays in C++, we can store
multiple values of same type which was not possible with normal variables. The values are
stored in indices of an array as shown below
// header file for input and output
#include <iostream>
// namespace to point towards methods
using namespace std;
int main()
{
// myArray of type integer holding 10 numbers
int myArray[10] = {1,2,3,4,5,6,7,8,9,10};
cout << endl;
// element at zeroeth index
cout << myArray[0];
return 0;
}
Output 1
Strings
An object that contains sequence of words is known as string. String plays a very important role
in C++ programming.
There are two types of strings om C++
C language type string
or
C++ language type modern string
Both arrays and strings occupy adjacent areas of memory. The array length is determined at the
design time but the string can change its length during the execution of a program.
/*In computer programming, a precompiled header is a (C or C++) header file that is compiled
into an intermediate form that is faster to process for the compiler. Usage of precompiled
headers may significantly reduce compilation time, especially when
applied to large header files, header files that include many other header files,
or header files that are included in many translation units.
*/
#include “stdafx.h”
// for input and output
#include <iostream>
// for our string variable
#include <string>
using namespace std;
int main ()
{
string MyStr;
cout << “What is your name ? “;
cin >> MyStr;
cout << “Hello ” + MyStr;
cout<< ” “;
return 0;
}
Output
What is your name? Adeel
Hello Adeel
C-string can not contain 0 as a character in them. C-strings are essentially null terminated
strings; hence the 0 contained in them is considered as end of the string. They can not hold 0
as character.
Important points
Windows is written in C++
Mac is written with Objective C but its kernel is in C and all IO PnP subsystem is Embedded
C++
Linux uses C language, other applications are written in C++

Weitere ähnliche Inhalte

Was ist angesagt?

SiriusCon 2017 - Integrating Xtext and Sirius: Strategies and Pitfalls
SiriusCon 2017 - Integrating Xtext and Sirius: Strategies and PitfallsSiriusCon 2017 - Integrating Xtext and Sirius: Strategies and Pitfalls
SiriusCon 2017 - Integrating Xtext and Sirius: Strategies and PitfallsObeo
 
Integrating Xtext and Sirius: Strategies and Pitfalls
Integrating Xtext and Sirius: Strategies and PitfallsIntegrating Xtext and Sirius: Strategies and Pitfalls
Integrating Xtext and Sirius: Strategies and PitfallsCédric Brun
 
What is Variables and Header files
What is Variables and Header filesWhat is Variables and Header files
What is Variables and Header filesAnuragSrivastava272
 
W3C HTML5 KIG-Typed Arrays
W3C HTML5 KIG-Typed ArraysW3C HTML5 KIG-Typed Arrays
W3C HTML5 KIG-Typed ArraysChanghwan Yi
 
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando BorrettiTryolabs
 
Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Deepak Singh
 

Was ist angesagt? (14)

SiriusCon 2017 - Integrating Xtext and Sirius: Strategies and Pitfalls
SiriusCon 2017 - Integrating Xtext and Sirius: Strategies and PitfallsSiriusCon 2017 - Integrating Xtext and Sirius: Strategies and Pitfalls
SiriusCon 2017 - Integrating Xtext and Sirius: Strategies and Pitfalls
 
Integrating Xtext and Sirius: Strategies and Pitfalls
Integrating Xtext and Sirius: Strategies and PitfallsIntegrating Xtext and Sirius: Strategies and Pitfalls
Integrating Xtext and Sirius: Strategies and Pitfalls
 
Ds lec 14 filing in c++
Ds lec 14 filing in c++Ds lec 14 filing in c++
Ds lec 14 filing in c++
 
Opps Concept
Opps ConceptOpps Concept
Opps Concept
 
Chapter 3 part2
Chapter 3  part2Chapter 3  part2
Chapter 3 part2
 
What is Variables and Header files
What is Variables and Header filesWhat is Variables and Header files
What is Variables and Header files
 
Strings
StringsStrings
Strings
 
W3C HTML5 KIG-Typed Arrays
W3C HTML5 KIG-Typed ArraysW3C HTML5 KIG-Typed Arrays
W3C HTML5 KIG-Typed Arrays
 
Using xml in a data set (ado.net)
Using xml in a data set (ado.net)Using xml in a data set (ado.net)
Using xml in a data set (ado.net)
 
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
 
Strings
StringsStrings
Strings
 
Rust - Fernando Borretti
Rust - Fernando BorrettiRust - Fernando Borretti
Rust - Fernando Borretti
 
C string
C stringC string
C string
 
Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++Chapter 7 - Input Output Statements in C++
Chapter 7 - Input Output Statements in C++
 

Ähnlich wie Programming in c plus plus4

C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...ANUSUYA S
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxWatchDog13
 
CPP-overviews notes variable data types notes
CPP-overviews notes variable data types notesCPP-overviews notes variable data types notes
CPP-overviews notes variable data types notesSukhpreetSingh519414
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptxDilanAlmsa
 
Abhishek lingineni
Abhishek lingineniAbhishek lingineni
Abhishek lingineniabhishekl404
 
CPlusPus
CPlusPusCPlusPus
CPlusPusrasen58
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++TemplatesGanesh Samarthyam
 
Namespace in C++ Programming Language
Namespace in C++ Programming LanguageNamespace in C++ Programming Language
Namespace in C++ Programming LanguageHimanshu Choudhary
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxSajalKesharwani2
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptInfotech27
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.pptTeacherOnat
 

Ähnlich wie Programming in c plus plus4 (20)

C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
C++primer
C++primerC++primer
C++primer
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptx
 
Objective c intro (1)
Objective c intro (1)Objective c intro (1)
Objective c intro (1)
 
CPP-overviews notes variable data types notes
CPP-overviews notes variable data types notesCPP-overviews notes variable data types notes
CPP-overviews notes variable data types notes
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptx
 
C++
C++C++
C++
 
Abhishek lingineni
Abhishek lingineniAbhishek lingineni
Abhishek lingineni
 
CPlusPus
CPlusPusCPlusPus
CPlusPus
 
Cpp-c++.pptx
Cpp-c++.pptxCpp-c++.pptx
Cpp-c++.pptx
 
An Introduction To C++Templates
An Introduction To C++TemplatesAn Introduction To C++Templates
An Introduction To C++Templates
 
Namespace1
Namespace1Namespace1
Namespace1
 
Namespace in C++ Programming Language
Namespace in C++ Programming LanguageNamespace in C++ Programming Language
Namespace in C++ Programming Language
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
PRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptxPRINCE PRESENTATION(1).pptx
PRINCE PRESENTATION(1).pptx
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 
C++_programs.ppt
C++_programs.pptC++_programs.ppt
C++_programs.ppt
 

Mehr von AA Coaching Academy

Mehr von AA Coaching Academy (7)

Indexers in C#
Indexers in C#Indexers in C#
Indexers in C#
 
New rich text document
New rich text documentNew rich text document
New rich text document
 
Programming in c plus plus3
Programming in c plus plus3Programming in c plus plus3
Programming in c plus plus3
 
Programming in c plus plus2
Programming in c plus plus2Programming in c plus plus2
Programming in c plus plus2
 
Advanced interview questions
Advanced interview questionsAdvanced interview questions
Advanced interview questions
 
Programming interview questions
Programming interview questionsProgramming interview questions
Programming interview questions
 
Professional erd models
Professional erd modelsProfessional erd models
Professional erd models
 

Kürzlich hochgeladen

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Kürzlich hochgeladen (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Programming in c plus plus4

  • 1. CPlusPlus arrays and strings Mr. A / 1 day ago image credit:http://wiki.codeblocks.org CPlusPlus arrays and strings CPlusPlus arrays and strings provide greater flexibility to store similar categories or types of values like integers, characters, decimals or even strings(to be discussed later) When we were using the variables in our previous post, what we were concluding was: A variable hold single value of certain type(s). With the facility of arrays in C++, we can store multiple values of same type which was not possible with normal variables. The values are stored in indices of an array as shown below
  • 2. // header file for input and output #include <iostream> // namespace to point towards methods using namespace std; int main() { // myArray of type integer holding 10 numbers int myArray[10] = {1,2,3,4,5,6,7,8,9,10}; cout << endl; // element at zeroeth index cout << myArray[0]; return 0; } Output 1
  • 3. Strings An object that contains sequence of words is known as string. String plays a very important role in C++ programming. There are two types of strings om C++ C language type string or C++ language type modern string Both arrays and strings occupy adjacent areas of memory. The array length is determined at the design time but the string can change its length during the execution of a program. /*In computer programming, a precompiled header is a (C or C++) header file that is compiled into an intermediate form that is faster to process for the compiler. Usage of precompiled headers may significantly reduce compilation time, especially when applied to large header files, header files that include many other header files, or header files that are included in many translation units. */ #include “stdafx.h” // for input and output #include <iostream> // for our string variable #include <string> using namespace std; int main () { string MyStr; cout << “What is your name ? “; cin >> MyStr; cout << “Hello ” + MyStr; cout<< ” “; return 0; } Output What is your name? Adeel Hello Adeel
  • 4. C-string can not contain 0 as a character in them. C-strings are essentially null terminated strings; hence the 0 contained in them is considered as end of the string. They can not hold 0 as character. Important points Windows is written in C++ Mac is written with Objective C but its kernel is in C and all IO PnP subsystem is Embedded C++ Linux uses C language, other applications are written in C++