Introduction to C + +: The Size of Operator, The Order of Precedence and Type Conversion

Doorsteptutor material for UGC Political-Science is prepared by world's top subject experts: Get detailed illustrated notes covering entire syllabus: point-by-point for high retention.

Download PDF of This Page (Size: 153K)

The Size of Operator

  • As we know that different types of variables, constant, etc. require different amounts of memory to store them.

  • The size of operator can be used to find how many bytes are required for an object to store in memory.

For Example, 8

size of (char) returns 1

size of (int) returns 2

size of (float) returns 4

  • If k is integer variable, the size of (k) returns 2.

  • The size of operator determines the amount of memory required for an object at compile time rather than at run time.

The Order of Precedence

  • The order in which the Arithmetic operators are used in a given expression is called the order of precedence.

  • The following table shows the order of precedence.

Image of Order of Precedence

Image of Order of Precedence

The expression in the following example is calculated from left or right.

Example 9

Type Conversion

The process in which one pre-defined type of expression is converted into another type is called conversion.

There are two types of conversion in C++.

  • Implicit conversion

  • Explicit conversion

Implicit Conversion

Data type can be mixed in the expression.

Example 10

  • When two operands of different type are encountered in the same expression, the lower type variable is converted to the higher type variable.

  • The following table shows the order of data types.

Image of Order in Data Type

Image of Order in Data Type

  • The int value of b is converted to type float and stored in a temporary variable before being multiplied by the float variable c.

  • The result is then converted to double so that it can be assigned to the double variable a.

Developed by: