Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
CPlusPlus arrays and strings
Mr. A / 1 day ago
image credit:http://wiki.codeblocks.org
CPlusPlus arrays and strings
CPlusP...
// header file for input and output
#include <iostream>
// namespace to point towards methods
using namespace std;
int mai...
Strings
An object that contains sequence of words is known as string. String plays a very important role
in C++ programmin...
C-string can not contain 0 as a character in them. C-strings are essentially null terminated
strings; hence the 0 containe...
Upcoming SlideShare
Loading in …5
×

Programming in c plus plus4

304 views

Published on

Arrays and Strings play very important role in programming. C++ provides those with elegance of true OOP

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Programming in c plus plus4

  1. 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. 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. 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. 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++

×