473,406 Members | 2,816 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.

looking for info about operators "?" and ":"

7
Hello all :)
could anyone give a guide, ebook etc.. about the operators "?" and ":"
thanks in advance
Leonid
Jan 5 '07 #1
4 1362
r035198x
13,262 8TB
Hello all :)
could anyone give a guide, ebook etc.. about the operators "?" and ":"
thanks in advance
Leonid
You don't need a book for those. That is just the short form for the if-else

int x = 5;
(x > 3) ? cout<<"greater than 3":cout<<"no";
//if(x >3)cout<<"greater than 3"; else cout<<"no";

play around with them on the compiler
Jan 5 '07 #2
Leonid
7
You don't need a book for those. That is just the short form for the if-else

int x = 5;
(x > 3) ? cout<<"greater than 3":cout<<"no";
//if(x >3)cout<<"greater than 3"; else cout<<"no";

play around with them on the compiler
thank you very much!
Jan 5 '07 #3
Leonid
7
sorry for the double postng' my limit for editing has exceed...

I got an error while writing this

#include <iostream.h>
#include <conio.h>

void main(void)
{
int a,b;
while(1)
{
cout<<"type 'e' for exit";
(getch()=='e')? break:continue;
cin>>a>>b;
(a>b)? cout<<""<<a<<endl:cout<<""<<b<<endl:cout<<"even"<< endl;
}
}

I got two errors
the first one was after the break
and the second was before the third condition.

thanks in advance
Leonid
Jan 5 '07 #4
horace1
1,510 Expert 1GB
The conditional operator ? is a ternary operator (it has three operands) in which the operands are three expressions. It takes the following general form:
expression1 ? expression2 : expression3

For example, consider the following if statement:
Expand|Select|Wrap|Line Numbers
  1.     if (x >= 0)  z = cos(x); else z = sin(x);
  2.  
This may be written:
Expand|Select|Wrap|Line Numbers
  1.      z = (x >= 0) ? cos(x) : sin(x);
  2.  
However, the following will not work
Expand|Select|Wrap|Line Numbers
  1.   (getch()=='e')? break:continue;
  2.  
because break and continue are statements and cannot be part of an expression.
The comiler will give an error message such as "expected primary-expression before break"
Jan 5 '07 #5

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

Similar topics

1
by: marks | last post by:
I get the same error trying to install any pear package if it's not alreay installed. # pear install Net_SMTP no signature found for package.info(string,string,bool) # pear -V PEAR Version:...
5
by: TPS | last post by:
When I set trace enable to true in my web.config file, the debug info does not display at the "bottom" of the page, it displays "under" all of my buttons, labels, grids etc. This behavior...
7
by: theyas | last post by:
How can I get my code to NOT display two "Open/Save/Cancel/More Info" dialog boxes when using the "Response.WriteFile" method to download a file to IE I've asked about this before and didn't get a...
4
by: Påhl Melin | last post by:
I have some problems using conversion operators in C++/CLI. In my project I have two ref class:es Signal and SignalMask and I have an conversion function in Signal to convert Signal:s to...
0
by: olimpia | last post by:
Hello, I am getting back to programming after many many years. Never work with Basic and now I am trying to work on a little project using Visual Basic.NET 2003 to verify info (at least 10 chars)...
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
5
bartonc
by: bartonc | last post by:
By that I mean they stop evaluation at the first True part of the expression. I use it often to replace an uninitialized object. Like this: >>> aString = "" >>> aString or "Hello, world" 'Hello,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.