how to ompare 2 conditions using an OR operator in c++ in linux environment.when i press the OR symbol key in the keyboard it shows some other symbol . i tried with all the keys. are there any alternate ways please do tell me

I would suggest that the root of your problem is that the keyboard layout setting you are using with Linux does not match that of the keyboard you are using. I suggest you look into setting the correct keyboard type for you Linux installation, as you will likely find other keys that are incorrectly mapped. For example on my Ubuntu distribution this can be done from the System->Preferences->Keyboard menu option on the Layout tab. You might also like to try other key and shift-key combinations to see if the symbol is in fact available but on some other key.

However, in C++ there are two ways to get around this problem: Use special multiple-character substitutes for the OR (also called the pipe) symbol called trigraph sequences (because they are sequences of 3 characters), or use the alternate keyword for the operators. There are in fact three operators using the pipe symbol: Boolean OR ( || ), bitwise OR ( | ), and of course there is the bitwise-or-equals operator ( |= ) ).

The trigraph sequence for the pipe symbol, |, is:


That is question mark, question mark, exclamation mark.

The alternate keywords (or tokens as the standard prefers to call them, probably because many of the operators are not words <g>) are:

   ||    or
   |     bitor
   |=    or_eq

Hopefully you are using a compiler that is up to date enough to recognise these alternate tokens for the usual operators. Note that if you are using the GNU compiler (g++), then a quick check using g++ 4.1.2 indicates that (current) g++ accepts the alternate tokens (or, bitor, or_eq) but not the trigraph sequence for the pipe symbol.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at http://www.open-std.org/jtc1/sc22/wg21/.


©2016 About.com. All rights reserved.