Academic Tutorials

English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting

C++ Tutorial
Introduction to C++
C++ Concepts
A C++ Program
Variables in C++
Operators in C++
Control Statements
C++ Functions
C++ Classes
C++ Objects
Constructors and Destructors
Pointers to the Classes
C++ Overloading
Friend Function
Virtual Functions
Exception Handling in C++
C++ Templates
C++ Summary

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
Apple Script
PL/SQL Tutorial
SQL Server
.NET (dotnet)
.Net Mobile
C# : C Sharp
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Assembly Language
Forth Programming
Lisp Programming
Data Warehousing
CGI Programming
Emacs Tutorial
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Operating System
Software Testing
SAP Module
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Financial Accounting
Managerial Accounting
Network Sites

Operators in CPP

Previoushome Next

Boolean Operators

and: && operator

//suppose that San is tired
bool sanIsTired = true;

//but San doesn't have to wake up early
bool sanMustWakeUpEarly = false;

//will San go to sleep now?
bool bedTime = sanIsTired && sanMustWakeUpEarly;

What will this chunk of the code do? It initializes the variables, sanIsTired to true and sanMustWakeUpEarly to false, The third line of code (comments not included), we determine that San is going to sleep if and only if "and" operation is true -- that is, if both the inputs to "and" operation are true. In this case, first input is true and second input is false. Since the "and" requires both inputs to be true in order for output to be true, but one of an inputs is false, output will become false. So, variable bedTime will store a false value.

not: !

"not" operator is used by placing symbol "!", before the boolean value.

//suppose that Julie stayed up late
bool julieStayedUpLate = true;

//will Julie be peppy tomorrow?
bool julieIsPeppy = !julieStayedUpLate;

This code illustrates the "not" operation. At the end of the code, variable julieIsPeppy will take an opposite value of julieStayedUpLate. If julieStayedUpLate were false, then the variable julianIsPeppy would be true. In this case, opposite is true, so the julieIsPeppy gets the value false.

The Arithmetic Operators

In addition to boolean operators, C++ has many arithmetic operators. They are listed below:

name symbol sample usage
addition + int sum = 4 + 7
subtraction - float difference = 18.55 - 14.21
multiplication * float product = 5 * 3.5
division / int quotient = 14 / 3
modulo ("mod") % int remainder = 10 % 6

These operators probably look familiar with an exception of mod (%) operator. Mod is simply a remainder produced by dividing the two integers. In example shown in the table above, if we treat a 10 / 6 as the integer divison, quotient is 1 (rather than being 1.666) and remainder is 4. Hence, a variable remainder will get a value 4.

Equality Operators

An equality operator is used to tests the condition like "is less than", "is greater than", and "is equal to". it is useful to to compare two numbers using the expressions like "x<y".

name symbol sample usage result
is less than < bool result = (4 < 7) true
is greater than > bool result = (3.1 > 3.1) false
is equal to == bool result = (11 == 8) false
is less than or equal to <= bool result = (41.1 <= 42) true
is greater than or equal to >= bool result = (41.1 >= 42) false
is not equal to != bool result = (12 != 12) false

Once using the equality operator is known,it is easy to use all the others. They all will work in the same way: they take an expressions on the either side of them, and will either returns true or false.

The Assignment Operators

In case of an assignment operators return value is simply the value which is stored in a variable on the left-hand-side.

int x;
int y;
x = 5;
y = 9;
cout << "The value of 'x' is "<< x << endl;
cout << "The value of 'y' is " << y << endl;
int sum;
sum = x + y;
cout << "The sum of 'x' and 'y' is " << sum << endl;

This block of code shows why one might want to throw the return value of the operator. Look at third line, x = 5. We are using an assignment operator here to place a value 5 in a variable x. Since the expression x = 5 returns the value, and we are not been using it, then you can say we are ignoring a return value.

What is an Operator Precedence?

An Operator precedence refers to a order in which the operators are resolved. An operator with a high precedence will be used before the operator with the lower precedence. Here is an example: operators have same precedence as the other operators in their group, and have the higher precedence than the operators in the lower groups.

operator name
! boolean not

* multiplication
/ division
% mod

+ addition
- subtraction

< is less than
<= is less than or equal to
> is greater than
>= is greater than or equal to

== is equal to
!= is not equal to

&& boolean and

|| boolean or

= assignment
*= multiply and assign
/= divide and assign
%= mod and assign
+= add and assign
-= subtract and assign

Be the first one to comment on this page.

  C++ Tutorial eBooks
More Links » »
 C++ Tutorial FAQs
More Links » »
 C++ Tutorial Interview Questions
More Links » »
 C++ Tutorial Articles
More Links » »
 C++ Tutorial News
More Links » »
 C++ Tutorial Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords Operators in CPP, c++ operators, java operators, operators in c++, cpp tutorial, operators in c#, functions cpp, cpp c++, cpp array, bitwise operators, bit operators, array operators, cpp example, cpp code, cpp program, logical operators, cpp function, algorithm cpp, arithmetic operators, operators xor, cpp source, shift operators, cpp h

HTML Quizzes
CSS Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
XML Quizzes
XML Quiz
XSL Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2022 Vyom Technosoft Pvt. Ltd., All Rights Reserved.