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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:52:44+00:00 2026-06-12T18:52:44+00:00

Possible Duplicate: Why would you use the ternary operator without assigning a value for

  • 0

Possible Duplicate:
Why would you use the ternary operator without assigning a value for the “true” condition (x = x ?: 1)

In one’s book I saw the vague (for me) syntax of ternary operator usage:

int nr = nr ? : 1; /* allowed shortcut, same as "nr ? nr : 1" */

What exactly this mean? Somewhere in the code the ‘nr’ variable is declared and it’s initial value is based on the comparison result whether the ‘nr’ (which has a junk inside it, I guess O_o) is not equal to zero… And if so then what value it would get?

  • 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-12T18:52:45+00:00Added an answer on June 12, 2026 at 6:52 pm

    This is an extension to the ternaray operator that allows the second operand to be omitted, as noted in the comment.

    This:

    int nr = nr ? : 1;
    

    Is equivalent to:

    int nr = nr ? nr : 1;
    

    I believe that this is a GCC-specific extension, here’s the GCC extension page for it.

    As others have pointed out in the comments, since nr is being declared and it’s value used in the declaration, the result of this line is unpredictable.

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

Sidebar

Related Questions

Possible Duplicate: Where would I use a bitwise operator in JavaScript? In c/c++ bitwise
Possible Duplicate: When to Use Static Classes in C# Questions in the title..........i would
Possible Duplicate: Why would someone use WHERE 1=1 AND <conditions> in a SQL clause?
Possible Duplicate: How can I replicate the trashing animation of Mail.app I would use
Possible Duplicate: When or why would you use a right outer join instead of
Possible Duplicate: Why would one declare a Java interface method as abstract? The following
Possible Duplicate: decimal vs double! - Which one should I use and when? I'm
Possible Duplicate: How will you use the C# 4 dynamic type ? What would
Possible Duplicate: Should I use double or float ? When would I rather use
Possible Duplicate: Why would someone use WHERE 1=1 AND <conditions> in a SQL clause?

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.