Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8395039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:12:07+00:00 2026-06-09T20:12:07+00:00

On compiling given program in GCC Compiler : int main() { int a=2,b=3; (a>1)?b=10:b=50;

  • 0

On compiling given program in GCC Compiler :

int main()  
{  
      int a=2,b=3;  
      (a>1)?b=10:b=50;  
      printf("%d",b);  
      return 0;     
}


it is showing error that “lvalue required as left operand”
but if i write 4th line as

(a>1)?b=10:(b=50);

Then its showing no compilation error . Can any one explain me why ?
And also how does it differ from if…else… ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:12:08+00:00Added an answer on June 9, 2026 at 8:12 pm

    As mentioned in the comments, you have an issue with operator precedence. Your code is interpreted as follows:

    ((a > 1) ? b = 10 : b) = 50;
    

    The above code is invalid for the same reason that writing (b = 10) = 50 is invalid.

    The code can be more clearly written as:

    b = a > 1 ? 10 : 50;
    

    And also how does it differ from if…else… ?

    The conditional operator works only with expressions as operands. An if statement can contain statements in the body.

    A conditional operator can always be replaced by an equivalent if statement. But the reverse is not true – there are if statements that cannot be replaced with an equivalent conditional operator expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple print program called print.c: #include <stdio.h> int main(void){ printf(Random
Problem Why would compiling a program which has an int main(void) main function differ
In compiling qt I found that there is a qws target called arm-linux-gcc. I
When compiling a c file that uses old style function definition like int foo(a)
So I have a project that I have been compiling on the apple-darwin11-llvm-g++-4.2 compiler.
While compiling a C program in LINUX, I get the foll. error: stream.h:1123: error:
My program is as follows; #include <stdio.h> #include <string.h> int main() { char string[]
I am having some difficulty compiling a C++ program that I've written. This program
i am compiling a simple Win32 api program but the problem is that it
I am compiling a C program with the SPARC RTEMS C compiler. Using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.