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 8348623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:44:55+00:00 2026-06-09T07:44:55+00:00

Why (a?b:c)=5; in ‘C’ shows lvalue required while *(a?&b:&c)=5; is perfectly fine? What is

  • 0

Why

(a?b:c)=5;

in ‘C’ shows lvalue required while

*(a?&b:&c)=5;

is perfectly fine? What is the difference between the two?

Assuming a=1, for first case, it gives b=5 and second case it gives, *(&b)=5.`

What i am not able to understand is: what difference does it make if we write b=5 or *(&b)=5?

  • 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-09T07:44:57+00:00Added an answer on June 9, 2026 at 7:44 am

    what difference does it make if we write b=5 or *(&b)=5?

    The second one gets a pointer to b and then dereferences that pointer, storing 5 into the obtained pointer.

    However, your question seems to be ignoring the real question: why it works in the second case but not the first. And that has to do with expressions in C and how they’re dealt with.

    The result of the ?: operator is a value; specifically, it is an rvalue. Loosely defined, an rvalue is a value that can’t go on the left-hand side of an assignment. They are so named because they’re values that go on the right-hand side of an assignment. For example, the expression “5” is an rvalue expression. You can’t do 5 = 40; that’s nonsense.

    A named variable is an lvalue. You can put an lvalue on the left-hand side of an equation. The expression a is an lvalue expression (assuming that a is a variable name that is in scope).

    However, the expression (a + b) is an rvalue expression, not an lvalue. And with good reason; you can no more do (a + b) = 30; than you could (5 + 10) = 30;.

    The result of the ?: operator is an rvalue expression, just as with the + operator above. This explains why (a?b:c) = 5; doesn’t work; you’re trying to assign a value to an rvalue expression. That’s illegal.

    Now, let’s look at the second case. We know that ?: results in an rvalue expression. Now, that explains what the classification of the expression is, but what about the type of the expression’s result? Well, assuming that b and c are both ints, the type of (a?b:c) is also int.

    However, when you do (a?&b:&c), the type of this expression is int*, not int. It is a pointer to an integer. It’s an rvalue expression of type “pointer to int.” It will return either the address of b, or the address of c.

    When you have an int*, and you dereference it with the * operator, what do you get? You get an lvalue expression of type int. Since (a?&b:&c) is an rvalue expression of type int*, if you dereference it, you will get an lvalue expression of type int. This lvalue will refer to either b or c, depending on the contents of a.

    To put it simply, it works exactly like this:

    int *ptr = NULL;
    if(a)
      ptr = &b;
    else
      ptr = &c;
    
    *ptr = 5;
    

    You get a pointer, which could point to any particular memory location, then you store something in the location being pointed to. It’s that simple.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I was writing code for dragging mechanism which invokes to wait for small period
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
This is how I get the tags of a body of text. var tags
I'm running a Octopress blog which is based on Jekyll . Now I wanted

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.