2 votes 2 votes Inside a program loop if we write *ch1++ it will give "lvalue required" error but without any loop if we write even ++*ch1++; it will not give any lvalue error. Why? Programming in C programming-in-c + – srestha asked Oct 24, 2017 edited Oct 24, 2017 by srestha srestha 639 views answer comment Share Follow See all 14 Comments See all 14 14 Comments reply Anu007 commented Oct 24, 2017 reply Follow Share ++*ch1++ = ++(*(ch1++)) which is equal to *(ch1++)= (*(ch1++))+ 1 *ch1++ here lvalue is not present 0 votes 0 votes AskHerOut commented Oct 24, 2017 reply Follow Share https://stackoverflow.com/questions/22603763/how-to-check-that-behavior-is-undefined-in-c 0 votes 0 votes srestha commented Oct 24, 2017 reply Follow Share no.. 0 votes 0 votes Anu007 commented Oct 24, 2017 reply Follow Share what ??? 0 votes 0 votes srestha commented Oct 24, 2017 reply Follow Share that is not my query. Read question carefully 0 votes 0 votes AskHerOut commented Oct 24, 2017 reply Follow Share #include <stdio.h> int main() { int c=10, *ch=&c, i=10; *ch++; while(i--){ *ch++; } printf("Hello, World!\n%d", *ch++); return 0; } This code isnt giving lvalue required error. I executed it on coding ground as well as online gdp. Isn't it what you were asking for? 0 votes 0 votes srestha commented Oct 24, 2017 reply Follow Share yes, that I know, it will not give lvalue error But put *ch++ inside while loop. then it will give lvalue error. Why so? that was my question 0 votes 0 votes AskHerOut commented Oct 24, 2017 reply Follow Share well in my case, its not giving any or probably I didnt get you. Did you mean putting it inside the condition part of while? 0 votes 0 votes srestha commented Oct 24, 2017 reply Follow Share yes, in the condition part means replace while(i--) with while(*ch++) and check 0 votes 0 votes AskHerOut commented Oct 24, 2017 reply Follow Share int main() { int c=10, *ch=&c, i=10; int count=0; while(*ch++){ printf("hey\n"); if(count++==3)break; } return 0; } No error at all. its printing hey 4 times as expected :/ 0 votes 0 votes srestha commented Oct 24, 2017 reply Follow Share :O but it is giving lvalue #include <stdio.h> int main(void) { char ch1[5]="GATE"; char *ptr-ch1; while(*ch1++) { printf("%c",*ch1); } return 0; } 0 votes 0 votes AskHerOut commented Oct 24, 2017 reply Follow Share srestha, ch1 is a constant pointer, you cant change its value -_- 2 votes 2 votes srestha commented Oct 24, 2017 reply Follow Share yes , that I know But why giving lvalue? 0 votes 0 votes AskHerOut commented Oct 24, 2017 reply Follow Share Because its treating ch1 as a constant, and you need to have a variable on the left hand side so that a value can be assigned to it. So if you write a constant on LHS you get an Lvalue required error. 2 votes 2 votes Please log in or register to add a comment.