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

  • SEARCH
  • Home
  • 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 8278183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:55:21+00:00 2026-06-08T08:55:21+00:00

The compiler gives an error on this statement. i>=3?b=10:b=5; error: lvalue required as left

  • 0

The compiler gives an error on this statement.
i>=3?b=10:b=5;

error: lvalue required as left operand of assignment

Not able to figure out why. Compiler being used is GCC.

  • 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-08T08:55:23+00:00Added an answer on June 8, 2026 at 8:55 am

    The problem is explained by operator precedence. In accordance with C grammar your

     i >= 3 ? b = 10 : b = 5;
    

    is interpreted by C compiler as

     (i >= 3 ? b = 10 : b) = 5;
    

    Firstly, this is probably not what you intended. Secondly, in C language the result of ?: operator is not an lvalue. You cannot assign anything to it. Hence the error message.

    In order to correct the problem (assuming I understand your intent correctly), you either have to use braces

     i >= 3 ? (b = 10) : (b = 5);
    

    or simply rewrite it in a more conventional way

     b = i >= 3 ? 10 : 5;
    

    As a side note, this happens to be one of the differences between C and C++ grammar. In C++ your original statement would be interpreted as i >= 3 ? (b = 10) : (b = 5) even without explicit braces. On top of that, in C++ the result of ?: can be an lvalue.

    In other words, in C++ your original statement would compile and work “as intended”, but not in C.

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

Sidebar

Related Questions

g++ compiler gives this error: expected `;' before 'it' template <typename T> class myList
The following code gives an unreachable statement compiler error public static void main(String[] args)
When i use this string as a sql command-string compiler gives me no error:
when I'm trying to compile my c program it gives me this error warning:
I'm curious to know why the C# compiler only gives me an error message
Turns out that g++ compiler (used in Qt Creator by default) gives a mere
I am not sure what the problem is but I keep receiving this error
The following code when compiled give this error I cannot understand why this is
When I try compile with maven 3.0.4, Eclipse give me this error: Failed to
Is there a standard/common way to give compiler-style error messages that point to a

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.