<< Chapter < Page Chapter >> Page >


\n : move to the next line

\t : move to the next tab

The bool Data Type

The C++ bool type can have two states expressed by the built-in constants true (which converts to an integral one) and false (which converts to an integral zero). All three names are keywords. This data type is most useful when a program must examine a specific condition and, as a result of the condition being either true or false, take a prescribed course of action.

Arithmetic operators

Most programs perform arithmetic calculations. Arithmetic operators are used to perform mathematical calculations, such as addition, subtraction, multiplication, and division in C++.

Arithmetic operators

A simple arithmetic expression consists of an arithmetic operator connecting two operands in the form:

operand operator operand


3 + 7

18 – 3

12.62 + 9.8




int main()


cout<<"15.0 plus 2.0 equals "<<(15.0 + 2.0)<<'\n'

<<"15.0 minus 2.0 equals "<<(15.0 - 2.0)<<'\n'

<<"15.0 times 2.0 equals "<<(15.0 * 2.0)<<'\n'

<<"15.0 divided by 2.0 equals "<<(15.0 / 2.0)<<'\n';

return 0;


The output of the above program:

15.0 plus 2.0 equals 17

15.0 minus 2.0 equals 13

15.0 times 2.0 equals 30

15.0 divided by 2.0 equals 7.5

Integer division

The division of two integers yields integer result. Thus the value of 15/2 is 7.

Modulus % operator produces the remainder of an integer division.


9%4 is 1

17%3 is 2

14%2 is 0

Operator precedence and associativity

Expressions containing multiple operators are evaluated by the priority, or precedence, of the operators.

Operator precedence defines the order in which an expression evaluates when several different operators are present. C++ have specific rules to determine the order of evaluation. The easiest to remember is that multiplication and division happen before addition and subtraction.

The following table lists both precedence and associativity of the operators.

Precedence and associativity of the operators

Example: Let us use the precedence rules to evaluate an expression containing operators of different precedence, such as 8 + 5*7%2*4. Because the multiplication and modulus operators have a higher precedence than the addition operator, these two operations are evaluated first (P2), using their left-to-right associativity, before the addition is evaluated (P3). Thus, the complete expression is evaluated as:

Expression evaluation

Expression types

An expression is any combination of operators and operands that can be evaluated to yield a value. An expression that contains only integer values as operands is called an integer expression, and the result of the expression is an integer value. Similarly, an expression containing only floating-point values (single and double precision) as operands is called a floating-point expression, and the result of the expression is a floating point value (the term real expression is also used).

Variables and declaration statements

One of the most important aspects of programming is storing and manipulating the values stored in variables . A variable is simply a name chosen by the programmer that is used to refer to computer storage locations. The term variable is used because the value stored in the variable can change, or vary.

Questions & Answers

what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Programming fundamentals in c++. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10788/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Programming fundamentals in c++' conversation and receive update notifications?