Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5842669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:02:52+00:00 2026-05-22T12:02:52+00:00

Why are the two following code segments not equivalent? void print (char* s) {

  • 0

Why are the two following code segments not equivalent?

void print (char* s) {
  if (*s == '\0')
     return;
    print(s+1);
   cout << *s;
}

void print (char* s) {
  if (*s == '\0')
     return;
    print(++s);
   cout << *s;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:02:52+00:00Added an answer on May 22, 2026 at 12:02 pm

    Since it looks like the OP changed print(s++) to print(++s), which is hugely different, here’s an explanation for this new version.

    In the first example, you have:

    print(s+1);
    cout << *s;
    

    s+1 does not modify s. So if s is 4, and you print(s+1), afterwards s will still be 4.

    print(++s);
    cout << *s;
    

    In this case, ++s modifies the local value of s. It increments it by 1. So if it was 4 before print(++s), it will be 5 afterwards.

    In both cases, a value equivalent to s+1 would be passed to the print function, causing it to print the next character.

    So the difference between the 2 functions is that the first one will recursively print character #0, then 1, 2, 3, …, while the second function prints 1, 2, 3, 4, … (it skips the first character and prints the “\0” afterwards).

    Example:
    For the s+1 version, print("hello") will result in h e l l o
    For the ++s version, print("hello") will result in e l l o \0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code is throwing two alerts as expected in IE but not in
The following two different code snippets seem equivalent to me: var myArray = Array();
Consider the following two segments of code in Java, Integer x=new Integer(100); Integer y=x;
The following code generates two CA2000 warnings (among others, but that's not the point).
I have two identical byte arrays in the following segment of code: /// <summary>
I have the following two code blocks. Code block 1 var checkboxes = $(div.c1
I have the following code that creates two objects (ProfileManager and EmployerManager) where the
I created the following code to calculate the duration between two timestamps which can
I have the following code in the top frame of a two frame page:
I have the following code which lets the user plot two points on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.