Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 141 - CoreGPT(Podar)_Flipbook_C8
P. 141

    Semicolon ( ; ): It is used to terminate a statement in C++.

                        Equal sign ( = ): It is used to assign a value to a variable.
                     Operators
                                                                                                              Operator
                     Operators  are  special  symbols  in  C++  that  are  used  to  perform
                     calculations. They are used along with operands or values to get the
                     desired result. For example:                                                  5  +  3
                     In the preceding example, 5 and 3 are the operands and + (plus) is an
                     operator. The plus operator is used to perform the addition operation.
                     Other operators are - (minus), * (multiply) and / (divide). We will learn
                                                                                                 Operands
                     more about operators in the next chapter.

                     Program 2: To calculate the sum of two numbers.

                     #include<iostream.h>
                     #include<conio.h>
                     void main()

                     {
                         clrscr();
                         int a, b, sum;

                         a = 10;                                 The sum of two numbers is:30_
                         b = 20;
                         sum = a + b;

                         cout<<"The sum of two numbers is:"<<sum;
                         getch();
                     }
                     C++ is a versatile language that allows the user to perform various mathematical operations.

                     These operations can be performed with the help of operators. In this chapter, you will learn
                     about various types of operators provided by C++.

                           OPERATORS

                     Operator is a symbol used to perform mathematical and logical calculations. C++ provides six
                     types of operators, which are:
                        Arithmetic Operators                                   Relational Operators
                        Logical Operators                                      Assignment Operators

                        Increment and Decrement Operators                      Ternary Operator
                     Arithmetic Operators

                     Arithmetic operators are general mathematical operators used to perform arithmetic operations.
                     These operators work on two operands. Hence, these operators are called binary operators.
                     C++ provides the following arithmetic operators:

                                                                                      Developing Programs in C++        139

| 136 137 138 139 140 141 142 143 144 145 146 |