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

  • Home
  • SEARCH
  • 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 6878359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:42:51+00:00 2026-05-27T04:42:51+00:00

void f(char * & pch) { cout << &pch << << pch << endl;

  • 0
void f(char  *  & pch) {
    cout << &pch << " " << pch << endl;
}

int main() {
    char *pch2 = new char[11];
    strcpy(pch2, "1234567890");
    cout << &pch2 << " " << pch2 << endl;
    f(pch2);

    return 0;
}

gives next output:

0xbfa0d62c 1234567890 
0xbfa0d62c 1234567890

but if i would modify first row as follows

void f(char const * const & pch) {

i will get:

0xbfec7df8 1234567890
0xbfec7dfc 1234567890

is difference in pointers appeared because of need to mark new memory cell as const or something else?

  • 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-27T04:42:51+00:00Added an answer on May 27, 2026 at 4:42 am

    pch2 is a char*, not a char const*. You cannot bind a reference of type char const*& to a pointer of type char*, so the following would be ill-formed:

    char* p(0);
    char const*& r(p);
    

    Similarly, if your function was declared as void f(char const*& pch), you would not be able to call it with a char* argument because of the const-qualifier mismatch.

    The reason that your example works is that a const reference can bind to a temporary, and the compiler can construct a temporary copy of your char* pointer, give that temporary the type char const*, and bind the reference pch to that temporary pointer.

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

Sidebar

Related Questions

consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
int main(void) { char *input; printf(prompt>); scanf(%s, input); printf(%s, input); return 0; } prompt>input
int main(void) { char tmp, arr[100]; int i, k; printf(Enter a string: ); scanf_s(%s,
int main(void) { char *p = hello; char *q = world; *p = *q;
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
#include <stdio.h> #include <stdlib.h> void getstr(char *&retstr) { char *tmp = (char *)malloc(25); strcpy(tmp,
I have a function: char *make_text(void) { char txt[MAXLEN]; //make something return txt; }
I'll illustrate my question with code: #include <iostream> void PrintInt(const unsigned char*& ptr) {
How do I do the following declaration? int main(int argc, char *argv[]) { char
void distinct (void) { char sent; int n1, n2, n3, n4, n5, n6, n7;

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.