Page 19 - Modular_V1.1_Flipbook
P. 19

Constants

                 A constant is a fixed value which does not change its contents during the program execution. In
                 C++, constants can be divided as follows:
                      Integer Constants:  An  integer  constant  is  a  numeric  value  without  any  fractions.  For
                      example: 10, -45, 35, 56, etc.

                      Floating-Point Constants: Any real number in which a fraction is denoted by a decimal
                      symbol. For example: 345.64, -867.22, 0.8763, etc.
                      String Constants: A string value is a collection of one or more characters written in single
                      or double quotes. For example: ‘A’, “Hello”, “Welcome to C++”, etc.
                 Delimiters

                 C++ allows some special characters in its coding called delimiters or punctuators. These are:

                 { } ( ) , ; =
                      Braces { }: These are used to specify the start and end of a block of code like main( )
                      function.

                      Parentheses ( ): These are used with the function name.
                      Comma ( , ): It is used to separate two variable declarations in same line.
                      Semicolon ( : ): It is used to terminate a program line 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()
                 {

                 int a, b, sum;
                 a = 10;
                 b = 20;
                 sum = a + b;
                 cout<<”The sum of two numbers is:”<<sum;
                 getch();
                 }



                                                                                         Getting Started with C++   17
   14   15   16   17   18   19   20   21   22   23   24