473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Ternary operator ((a>b)?a:b) inside return statement?

Is it possible to write "return" function inside a conditional operator as shown below?

a>b? return a: return b;
May 24 '07 #1
6 22836
Savage
1,764 Expert 1GB
Is it possible to write "return" function inside a conditional operator as shown below?

a>b? return a: return b;
Yes,but it would be:

return(a>b)?a:b;

Savage
May 24 '07 #2
sicarie
4,677 Expert Mod 4TB
I've changed the title of the thread to better describe the issue - please let me know if you don't think it does (and what you want it to be).
May 24 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
Is it possible to write "return" function inside a conditional operator as shown below?

a>b? return a: return b;
No. If you try this it won't compile.

The ternary operator requires expressions but not code. You can, however, call a function because the function becomes an instance of its return type so you get the return value from the operator.
May 24 '07 #4
svlsr2000
181 Expert 100+
No. If you try this it won't compile.

The ternary operator requires expressions but not code. You can, however, call a function because the function becomes an instance of its return type so you get the return value from the operator.
But most of the book defines terinary operator as
Condition ? expression 1: exression 2;

My doubt : Is return statement is a expression or not.
May 24 '07 #5
JosAH
11,448 Expert 8TB
how about a>b?return a; return b;
That won't work; 'return' is a statement and the ternary operator ?: wants
expressions. It just won't compile.

kind regards,

Jos
May 24 '07 #6
svlsr2000
181 Expert 100+
That won't work; 'return' is a statement and the ternary operator ?: wants
expressions. It just won't compile.

kind regards,

Jos
Oh i got it, i think i really need a long break during this weekend. :)
May 24 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: praba kar | last post by:
Dear All, I am new to Python. I want to know how to work with ternary operator in Python. I cannot find any ternary operator in Python. So Kindly clear my doubt regarding this ...
4
by: marco_segurini | last post by:
Hi, I am wondering if there is a way to use the ternary operator to select a function, between two, even if at least one of them is overloaded. Ex: void f1(int) {} void f1(double) {} void...
4
by: Bob Gregory | last post by:
Hi all, I don't actually have a mac with which to test this, but I'm informed by a colleague that one of my scripts has failed in IE on the Mac; endless twiddling seems to point to the ternary...
6
by: glongword | last post by:
As the assert macro should evaluate to a void expression, it should not have an 'if statement' in its definition. Does this necessitate the existence of a ternary conditional operator? Is there a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
48
by: Daniel Crespo | last post by:
Hi! I would like to know how can I do the PHP ternary operator/statement (... ? ... : ...) in Python... I want to something like: a = {'Huge': (quantity>90) ? True : False} Any...
15
by: Arthur Dent | last post by:
Hi all, im just curious if anyone knows..... With .NET 2, VB didnt happen to get a true ternary operator, did it? Stuck away in a corner somewhere? By ternary, i mean something like C's a?b:c...
8
by: Bob Hoeppner | last post by:
In the following code //add to bool or double Dictionary this.m_unit.Add((unittype == "b")? unitnum:(double)unitnum); The bool dictionary uses an integer index, the double uses a double...
9
by: lawpoop | last post by:
I'm trying to write some simple code, but I might be simplifying it too much. I have a function that either returns a string that I want, or FALSE. In the code that I'm working on, I would like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.