313 views
0 votes
0 votes
#include <stdio.h>
 
int make_it(int *x,int *y, int *z){
	*x *= *y+*z;
	*y=*x<<1;
	*z=*x+*y;
}
 
 
int main(void) {
	int a=5, b=10;
	printf("%d%d",a,b);
	make_it(&b,&a,&(a+b));
	printf("%d%d",a,b);
	return 0;
}

Why this code is giving lvalue error?

1 Answer

0 votes
0 votes
int main(void) {
	int a=5, b=10;
	printf("%d%d",a,b);
	make_it(&b,&a,&(a+b));  <== Here &(a+b) returns the error.
	printf("%d%d",a,b);
	return 0;
}

Since you have declared a and b as integers, a+b returns an integer value (not a variable). So the unary & fails because no address is available. Check the example below:

#include <stdio.h>

int main()
{
     int a=5,b=10;
    printf("%d", &(a+b));

    return 0;
}

$gcc -o main *.c
main.c: In function ‘main’:
main.c:7:18: error: lvalue required as unary ‘&’ operand
     printf("%d", &(a+b));
                  ^

Related questions

0 votes
0 votes
0 answers
1
aambazinga asked Sep 19, 2018
825 views
does the expression &A has l-value or not?iknow it will have r-value. but i think it will have l-value too. as in the scanf("%d",&A); isn't &A acting like l-value??pleas...
1 votes
1 votes
0 answers
2
Registered user 7 asked Aug 28, 2016
197 views
explain in brief L value required error
0 votes
0 votes
0 answers
3
Gurdeep Saini asked Jan 23, 2019
338 views
why this program given run time error #include<stdio.h int main ( ) { int x = 2, y = 5; if (x < y) return (x = x+y); else printf(“%d “,x); printf(“%d”,y); }https:...
1 votes
1 votes
1 answer
4