C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 2)
2.
Which of the following statements are correct about the below program?
#include<stdio.h>
int main()
{
    int i = 10, j = 15;
    if(i % 2 = j % 3)
        printf("IndiaBIX\n");
    return 0;
}
Error: Expression syntax
Error: Lvalue required
Error: Rvalue required
The Code runs successfully
Answer: Option
Explanation:

if(i % 2 = j % 3) This statement generates "LValue required error". There is no variable on the left side of the expression to assign (j % 3).

Discussion:
20 comments Page 1 of 2.

Dhinesh said:   7 years ago
Thanks @Sundar.

Natasha said:   7 years ago
Thanks @Sundar.

Nikhil said:   8 years ago
Thanks @Sundar.
(1)

Ravi mishra said:   8 years ago
Please tell me the meaning of Lvalue.

Prashant3393 said:   8 years ago
Thanks @Sundar.

Anjali said:   9 years ago
Nice explanation, thanks @Sundar.

Anonymous said:   10 years ago
@Navi.

It should be:

#include<stdio.h>
int main()
{
int i = 10, j = 15, a, b;
if((a=i % 2) == (b= j % 3))
printf("IndiaBIX\n");
return 0;
}

Navi said:   1 decade ago
/* Note: GCC Compiler (32 Bit Linux Platform). */

Then this is also not working why?

#include<stdio.h>
int main()
{
int i = 10, j = 15, a, b;
if((a=i % 2) = (b= j % 3))
printf("IndiaBIX\n");
return 0;
}

Franco said:   1 decade ago
L value always must be a variable and should not be a constant.

R value always must be a constant to assign for that variable.
(1)

Sameer said:   1 decade ago
@sundar,
as you mention at above explanation of if's valid condition example 4th one is false but not true..


Post your comments here:

Your comments will be displayed after verification.