# Category: Operators in C++

sizeof operator in C++ is an unary operator which can be used to find the size of the data-type or expression or a variable. It returns the size of the memory allocated (in Bytes) by the compiler. Lets say, we want to find the size of the memory allocated to the data-type int. We can find it by using sizeof operator as shown in the below code: #include<iostream.h> #include<conio.h> void main() { clrscr(); int sizeOfInt; sizeOfInt = sizeof(int); cout << sizeOfInt << ” Bytes”; getch(); } Output: 2 Bytes As you can see, the above code calculated the size of...

Simple conditional operations can be carried out with the conditional operator (? :). An expression that makes use of the conditional operator is called a conditional expression. Such an expression can be written in place of the more traditional if – else statement. A conditional expression is written in the form: expression 1 ? expression 2 : expression 3 While evaluating a conditional expression, expression 1 is evaluated first. If expression 1 is true (i.e., if its value is non-zero), then expression 2 is evaluated and this becomes the value of the conditional expression. However, if the expression 1 is...

There are several different assignment operators in C Plus Plus (C++). All of them are used to form assignment expressions, which assign the value of an expression to an identifier. The most commonly used assignment operator is =. Assignment expressions that make use of this operator are written in the form: identifier = expression where, identifier generally represents a variable, and expression represents a constant, a variable or a more complex expression. Example: a = 3; x = y; sum = a + b; In the above statements, the first assignment expression causes the integer value 3 to assigned to...

A logical operator is used to compare or evaluate logical and relational expressions. There are three logical operators in C Plus Plus (C++) language. They are: Operator Meaning && Logical AND || Logical OR ! Logical NOT An expression involving && or || is sometimes called compound expressions, since the expression involves two other expressions, that is, each of these operators (&& and ||) takes two expressions, one to the left and another to the right. Example of && operator: Consider the following expression: a > b && x == 10 The expression on the left is a > b...