Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 3P

Palindrome testing with pointers

This Practice Program requires that you read the optional section about pointer arithmetic. Complete the function isPalindrome so that it returns true if the string cstr is a palindrome (the same backwards as forwards) and false if it is not. The function uses the cstring library.

bool isPalindrome(char* cstr)

{

char* front = cstr;

char* back = cstr + strlen(cstr)−1;

while (front < back)

{

// Complete code here

}

return true;

}

 Here is a sample main function for quick and dirty testing:

int main()

{

char s1[50] = "neveroddoreven";

char s2[50] = "not a palindrome";

cout << isPalindrome(s1) << endl; // true

cout << isPalindrome(s2) << endl; // false

return 0;

}

Blurred answer
Students have asked these similar questions
You can dereference a smart pointer with the * operator. True False
Submerging is the phenomenon wherein the pointer vanishes when you move it too quickly.
C++ code  NB: Pointers must be used

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License