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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:24:57+00:00 2026-06-15T12:24:57+00:00

Statement *p++ = *source++; in the following first program doesn’t cause any errors but

  • 0

Statement *p++ = *source++; in the following first program doesn’t cause any errors but causes the error ISO C++ forbids cast to non-reference type used as lvalue in the second program when compiled. Why does this happens?

  • The first program

    #include 
    
    char *my_strcpy(char *destination, char *source)
    {
        char *p = destination;
        while (*source != '\0')
        {
            *p++ = *source++;
        }
        *p = '\0'; 
        return destination;
    }
    
    int main()
    {
        char source[] = "A string to be used for demonstration purposes";
        char destination[80];   
        my_strcpy(destination, source);
        puts(destination);
        return 0;
    }
    
  • The second program

    #include 
    
    char source[] = "A string to be used for demonstration purposes";
    char destination[80];
    
    int main()
    {
        char *p = destination;
        putchar('\n'); 
        while(*source != '\0') 
        {
            *p++ = *source++; 
        }
        *p = '\0';
        puts(destination);
        return 0;
    }
    
  • 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-15T12:24:59+00:00Added an answer on June 15, 2026 at 12:24 pm

    This happens because your first program increments a pointer, while in the second program you apply the ++ operator to an array. Although arrays often behave like pointers, they are not pointers. Arrays support pointer arithmetics, but they do not support pointer operators that treat them as lvalue (i.e. attempt to modify where they point).

    Fixing the problem is trivial – simply create a pointer that points to the array, and use that pointer in your loop, like this:

    char *p = destination;
    putchar('\n'); 
    char *src = source;
    while(*src != '\0') 
    {
        *p++ = *src++; 
    }
    *p = '\0';
    puts(destination);
    return 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my application, i am using following statement for display a image menuUserImage.Source =
Somehow, I'm getting the following error when executing a bit of source code that
I executed the following statement but it only updates the price rows of all
I tried to set the following SQL statement into Row Source property in Access
In this statement, taken from the Pagerank source code: Pattern.compile(\\[.+?\\]); What does the pattern
Using a SELECT statement in MS SQL 2005 TSQL, and no source table, just
Is there any open source software for converting SQL statements to LINQ?
This statement is returning error 00920- invalid relational operator. I am sure it is
The following code Ruby code will iterate the source string and produce a list
the website in the main document includes a javascript file using the following statement:

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.