in Programming in C retagged by
1,342 views
0 votes
0 votes
#include<stdio.h>
int  main()
{

   int i=10;
    printf("address of i=%d  value of i=%d",&i,i);
    &i=7200;
    printf("address of i=%d  value of i=%d",&i,i);
    
    return 0;
}
in Programming in C retagged by
1.3k views

1 comment

Lvalue error would come..
1
1

2 Answers

3 votes
3 votes

#include<stdio.h>
int  main()
{

   int i=10;----------------------------------------------------------------------------- Line 1
    printf("address of i=%d  value of i=%d",&i,i);-------------------------Line 2
    &i=7200;----------------------------------------------------------------------------Line 3
    printf("address of i=%d  value of i=%d",&i,i);-------------------------Line 4
    return 0;
}

In line 3, there will be L value error.

.

L-Value stands for left value

L-Value of Expressions refer to a memory locations

In any assignment statement L-Value of Expression must be a container(i.e. must have ability to hold the data)

Variable is the only container in C programming thus L Value must be any Variable.

3 Comments

*p = a;

is also valid for a pointer p and *p returns an l-value. But if we typecast it, we get a r-value.
0
0

@akash

link here

link here

actually & is a rvalue operator, cannot use as lvalue. Typecasting any lvalue will not be anymore a lvalue.

It is something like 0x12345=&a which is wrong so you are getting l-value is required. rt? @Arjun Sir

0
0
@Srestha & is an operator and so is typecast. And both of them returns an r-value.
0
0
0 votes
0 votes

lvalue and lvalue -:

An lvalue refers to an object that persists beyond a single expression. You can think of an lvalue as an object that has a name. All variables, including nonmodifiable (const) variables, are lvalues. An rvalue is a temporary value that does not persist beyond the expression that uses it. (https://msdn.microsoft.com/en-IN/library/f90831hc.aspx)

Here &i gives a particular value temporarily,which is itself a data not some kind of memory that can store data.

Related questions