Category: Operators in C++

sizeof operator 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:

Output:

As you can see, the above code calculated the size of int data type and displayed the result in C++.

Conditional Operator in C++

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...

Assignment Operators in C++

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:

In the above statements, the first assignment expression causes the integer value 3 to assigned to the variable a, and the second assignment causes the value...

Logical Operators in C++

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:

The expression on the left is a > b and that on the right is...