search
Log In
2 votes
181 views

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?

in Programming
edited by
181 views
0
++*ch1++ = ++(*(ch1++)) which is equal to *(ch1++)= (*(ch1++))+ 1
*ch1++ here lvalue is not present 
0
no..
0
what ???
0
that is not my query. Read question carefully
0
#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
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
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
yes, in the condition part

means replace while(i--) with while(*ch++) and check
0
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
: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;
}
2
srestha, ch1 is a constant pointer, you cant change its value -_-
0
yes , that I know

But why giving lvalue?
2
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.

Please log in or register to answer this question.

Related questions

0 votes
1 answer
1
883 views
#include<stdio.h> #include<stdlib.h> int main(void) { int maxLineCount = 500, maxCharCount = 500, index, j, count; char *line = NULL; size_t size; char *a[maxLineCount]; for (index = 0; index < maxLineCount; index++) a[index] = (char *)malloc(maxCharCount * ... of the code is doing. suppose we have 3 string given as input in 3 different lines then how can we access each character of the string?
asked Jun 1, 2019 in Programming Satbir 883 views
0 votes
0 answers
2
193 views
https://gateoverflow.in/45555/c-programming-predict-the-output main() { { extern int i; int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i; rude explained how output is printed but its giving error when i'm trying to run the program here https://ideone.com/xteXgV
asked Nov 10, 2018 in Programming Mk Utkarsh 193 views
0 votes
1 answer
3
256 views
#include <stdio.h> int main () { int c; while ((c = getchar ()) != EOF) { putchar (c); printf ("*"); } return 0; } when i run this program, the output i get is as qwerty q * w * e * r * t * y * * i'm not getting how this last "*" is ... the thing is, why the last * is getting printed in the next line. is it like putchar() returns and shift the printing pointer to new line? please clear my doubt..
asked Jul 21, 2018 in Programming aambazinga 256 views
0 votes
1 answer
4
200 views
What will be time complexity of the program? Explain?? #include<stdio.h> int main(){ int i,count=0; for(i=1 ; i<=n ; i++) { for(i=1 ; i<=$n^4$ ; i++) for(i=1 ; i<=$n^3$ ; i++){ count++; printf("%d\n",count); } } }
asked Jul 11, 2018 in Programming sumitr 200 views
...