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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:16:58+00:00 2026-05-22T19:16:58+00:00

I understand this is part of the basic stuff, but i am stuck :-(

  • 0

I understand this is part of the basic stuff, but i am stuck 🙁
Can someone please help me?

Program 1:

#include <stdio.h>
#include <stdlib.h> 

int main()
{
 int a=1,b=2,c;
 c=(a+b)++;
}

Why is the output an error? lvalue required?

Program 2:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
 char *p1="name";
 char *p2;

 p2=(char*)malloc(20);
 memset(p2,0,20);

 while(*p2++=*p1++);
 printf("%s\n",p2);

}

Why is the output, an empty string? And if i reverse the order of increment, that is: while(++*p2=++*p1);, why the lvalue error comes?

  • 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-22T19:16:59+00:00Added an answer on May 22, 2026 at 7:16 pm

    For the first question,(a+b)++ means “increment the value of a+b by 1″.

    You cannot increment a+b, though, for it’s not a variable. What would you expect to happen in the following code?

    int a = 1, b = 2;
    printf("a = %d, b = %d, a+b = %d\n", a, b, a+b);
    (a+b)++;
    printf("a = %d, b = %d, a+b = %d\n", a, b, a+b);
    

    Clearly the first printf should print

    a = 1, b = 2, a+b = 3

    But what about the second one?

    a = ?, b = ?, a+b = 4

    It’s not clear what a or b should be if we increment the sum.

    As for the second question, remember that you’re changing p2 when you copy over the data, so when you ask to print out what it’s pointing at, it’s pointing at the end of the string, not the beginning.

    An easier way to do the string copy would be to use strcpy, like so:

    strcpy(p2, p1);
    

    Note, this is only safe because you know that the size of the string in p1 isn’t greater than the size of p2. If you’re not sure about the size of the string (for instance, if you get the string from user input), you’ll need to be careful, as is outlined on Wikipedia.

    As for why while(++*p2=++*p1); doesn’t work, while while(*p2++=*p1++); does:

    Postfix-++ has higher precedence than *. This means, *p2++ means *(p2++).
    So

    *(p2++) = something;
    

    is the same as

    *p2 = something;
    p2 += 1;
    

    Meanwhile, ++*p2 means ++(*p2), or “whatever p2 points to, incremented by one”.

    Again, you get the problem, if you say:

     int a = 5, *p2 = &a;
     ++*p2 = 10;
     printf("a = %d\n", a);
    

    What would you expect this to print? If anything, it should print 9, because you’re telling the compiler that *p2+1 = 10.

    You can’t expect a C-compiler to solve that equation, however, so in order to keep the language simple and efficient, this sort of thing is forbidden.

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

Sidebar

Related Questions

I cannot understand how this is possible. Please help!! I have an app with
I don't know much about database optimization, but I'm trying to understand this case.
Lutz Roeder's Reflector, that is. Its obfuscated. I still don't understand this. Can somebody
I'm trying to understand why this does not work. (Basic example with no validation
I'm trying to understand this bit of code: in display.php: <html> ... <body> <table>
If I understand this correctly: Current CPU developing companies like AMD and Intel have
While I understand this question is fairly vague since I'm not giving you all
I'm confused with how views are organized, and it is important to understand this
I fail to understand why this code won't compile ExecutorService executor = new ScheduledThreadPoolExecutor(threads);
I would like to know this to understand why some games like Mario is

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.