•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 401,496 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,197 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 1370 | Replies: 2
![]() |
•
•
•
•
Originally Posted by Sukhbir
PLS EXPLAIN ME.char *ptr="abc"; char *ptr1; while(*ptr1++=*ptr++); //IT IS WORKING while((*ptr1)++=(*ptr)++); //ERROR
You haven't initialized ptr1: when you first dereference it, it is already undefined behavior, so "IT IS WORKING" is just plain "luck(?)".
In the "ERROR" line, the result of the ++ operator is not an lvalue, so it cannot be assigned to.
•
•
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation:
Rep Power: 5
Solved Threads: 10
Sukhbir, you have a lot of interesting syntax questions, and they are all covered in one chapter of any good C book, because these questions all revolve around the way the C compiler (and thus the C++ compiler) has been specified to work. You can also go into the help for your compiler and look for 'precedence'; there is a nice table that lists the exact order specified by the language.
In your first example,
*ptr1++
is the same as
*(ptr1++)
to the compiler, thus your second example, where you supplied the parens, would be different. In general, when writing code like this that might confuse someone, it is nice to put in the parens explicitly, even if they are not strictly needed by the compiler.
Dave's comments are also right on.
In your first example,
*ptr1++
is the same as
*(ptr1++)
to the compiler, thus your second example, where you supplied the parens, would be different. In general, when writing code like this that might confuse someone, it is nice to put in the parens explicitly, even if they are not strictly needed by the compiler.
Dave's comments are also right on.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- switch statement on String in Java (Java)
- Its really a problem on INSERT statement (MySQL)
- Sockets problem (Java)
- % problem (Java)
- Problem with Switch statement ? (C++)
- i have problem with array plz help (Java)
- Program Problem with a select statement to access Data base (C)
Other Threads in the C++ Forum
- Previous Thread: 128bit arithmetic
- Next Thread: Need Help counting Array Length



Linear Mode