Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
Question
Book Icon
Chapter 12.2, Problem 12.1CP
Program Plan Intro

Character by character text processing:

  • Strings can be accessed or manipulated by using an individual text that is present.
  • Different programming language access the string individually in a different way, some prefer the string gets accessed through subscript notation.
  • String is considered as list of characters.

Accessing string using subscript notation:

  • The string that are accessed using the subscript notation uses subscript “0” to hold the first character and similarly till the last character.
  • The last character of the string will be “\0”.
  • The first value the index value will be “0” and to find the last character use “length(variable)-1”

Example:

//declare and define a string

Declare String txt = "Hai"

Explanation:

In the above declaration, the given string  gets processed in the following way:

txt[0] will hold “H”.

txt[1] will hold “a”.

txt[2] will hold “i”.

Blurred answer
Students have asked these similar questions
True or False You cannot store a string in a variable of the char data type.
Assume the following variables are defined: char ch; double interest ; string name ; Assign each variable to a value of the correct data type.
The following code intends to input a user’s first name, last name, and age.However, it has an error. Fix the code.string fullName;int age;cout << "Enter your first and last name." << endl;cin >> fullName;cout << "Enter your age." << endl;cin >> age;cout << "You are " << age << " years old, " << fullName << endl;

Chapter 12 Solutions

Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT