retagged by
586 views
0 votes
0 votes

#include<stdio.h>
void test(int);
void test1(int *);
int main() { 
    int x = 30, *s = &x;
    test(x++);           //test(30++) ...statement P                         
    test1(s++);        //test(some  address++) ...statement S
    return 0;
}

void test(int x){
    printf("%d\n",x);
}

void test1(int *s){
    printf("%d\n",*s);
}

My doubt is why are we not getting L-value error in both the cases?

The program correctly outputs 

30

31

retagged by

1 Answer

Best answer
1 votes
1 votes

No both will not give lvalue error

Because, in 1st case 30 is an integer value which is inside a variable x and it is incremented, means operation is just post increment

x will replace with integer value, if it is a macro expansion. Then it will give lvalue error

Secondly, s is a pointer here. And pointer increment doesnot give lvalue error. Pointer gives lvalue error, when array value which works like pointer , need to pre or post increment. So, second one will also not give any error.

selected by

Related questions

2 votes
2 votes
1 answer
1
rupamsardar asked Aug 30, 2023
501 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...
0 votes
0 votes
1 answer
2
SHWETAV SUMAN asked Oct 6, 2022
344 views
i have typed the following code but when i executed it the solution was not according to my expectation.unsigned short int y= -9; int iy=y; printf(“%d”,iy); solutio...
0 votes
0 votes
3 answers
3
ykrishnay asked May 30, 2022
1,098 views
int main(){extern int a = 20;printf("%d",a); }//why this gives error but followig code is not extern int a =20;int main(){printf("%d",a); } //why this happens that first ...
0 votes
0 votes
0 answers
4
ykrishnay asked May 20, 2022
388 views
What is stream in c programming ? as i read file io in c programming so thats where i read “stream” word so what stream means ? thank you