473,788 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
Hello all :)
could anyone give a guide, ebook etc.. about the operators "?" and ":"
thanks in advance
Leonid
Jan 5 '07 #1
4 1389
r035198x
13,262 MVP
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<<"great er than 3"; else cout<<"no";

play around with them on the compiler
Jan 5 '07 #2
Leonid
7 New Member
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<<"great er than 3"; else cout<<"no";

play around with them on the compiler
thank you very much!
Jan 5 '07 #3
Leonid
7 New Member
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<<en dl:cout<<""<<b< <endl:cout<<"ev en"<<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 Recognized Expert Top Contributor
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
2391
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: 1.3.3 PHP Version: 5.0.3 Zend Engine Version: 2.0.3
5
2025
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 happens in GridLayout, or FlowLayout. ? Thanks, TPS.
7
3706
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 satisfactory answer (check your browser) so now that I've had the time to set up a reasonable little test that I can post somewhere, I'll try again. The app I've written has three ASPX pages. One is a combined page which writes a little text...
4
2908
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 SignalMask:s. The reason is I have a free function called WaitSignal that accepts av SignalMask where Signals parameters are supposed to implicitly be converted to SignalMask:s. I'm using the SignalMask class because I want to be able to supply a logic...
0
1322
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) entered by a user and compare if that data exist in the specific field of a Oracle database. I got the connection to the db all done, the dataset created and the form to ask for the information, but I am having problems to make the comparison with...
25
2585
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 constants in Python language. There are some workarounds available, for example the const-module. To me, this looks quite cumbersome and very unintuitive. For the interpreter, in the efficiency-wise, I just cannot tell.
5
2032
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, world' >>> anObject = None >>> anObject or range(5) >>> anObject = dict(a=1) >>> anObject or range(5)
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10173
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.