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 8009351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:25:26+00:00 2026-06-04T18:25:26+00:00

To my knowledge the standard strcmp function looks something like this: int strcmp(const char*

  • 0

To my knowledge the standard strcmp function looks something like this:

int strcmp(const char* string1, const char* string2)
{
    while(*pString1++ == *pString2++)
    {
        if(*pString1 == 0) return 0;
    }
    return *pString1 - pString2;
}

My question is that wouldn’t this increment the pointers passed into strcmp? In the following example it seems like it would trash the pointers and cause invalid stuff to happen.

const char* string1 = "blah";
const char* string2 = "blah";
const char* string3 = "blah";
if(strcmp(string1, string2) {doSomething();} 
// Won't this make string1 = "" because it incremented the pointer to the end?
else if (strcmp(string1, string3) {doSomethingElse();}

Sorry I’m just confused because it seems like if I pass a pointer into strcmp, I shouldn’t expect that pointer to suddenly hold an empty string. It seems like strcmp should take const char* const. Am I totally misunderstanding something?

  • 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-06-04T18:25:29+00:00Added an answer on June 4, 2026 at 6:25 pm

    Your misunderstanding is this: Arguments are passed by value (copy), but you seem to think they are passed by reference.

    You could get your expected behaviour by declaring the parameters to strcmp as references, like this:

    int strcmp(const char*& string1, const char*& string2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to C, so I apologize if this is pretty standard knowledge..
My knowledge of Lambda expressions is a bit shaky, while I can write code
My SQL knowledge is very limited, specially about SQLite, although I believe this is
Is good knowledge of PHP needed to make an installable template for CMS like
I know this is more like a serverfault question than a stackoverflow question, but
So my assignment is this: Using your knowledge of square roots in addition to
There is a table in our database that acts very much like a standard
I've got some nested objects like this: object Routes { object admin { def
Whilst looking for a C++ implementation of Excel's NORMDIST (cumulative) function I found this
I am following this tutorial http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics . As per this tutorial,when i pass 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.