Skip to main content

Most Visited Blog

How to Install minGW C++ compiler for Windows - Cyborg Coding

C++ Misc Operators - Cyborg Coding

C++ includes several miscellaneous operators that are less commonly used but are still important to know. Some of the most notable of these operators are:

Ternary operator (? :): This operator is a shorthand for an if-else statement. It takes three operands: a condition, an expression to evaluate if the condition is true, and an expression to evaluate if the condition is false. It evaluates the condition, and if it is true, it returns the value of the second expression; otherwise, it returns the value of the third expression.

sizeof operator: This operator is used to determine the size of a variable or data type in bytes.

Type cast operator: This operator is used to explicitly convert a value from one data type to another.

Pointer operator: This operator is used to access the memory location of a variable, it can be used to access the value stored in the memory location, it is represented by the * symbol.

Address-of operator: This operator is used to get the memory address of a variable, it is represented by the & symbol.

Here's an example of how these operators can be used:

int x = 5;
int y = 2;

int max = (x > y) ? x : y; // max is 5

int a[5];
int size = sizeof(a); // size is 20, because an int is 4 bytes and there are 5 elements in the array

float f = 2.5;
int i = (int)f; // i is 2

int *p = &x; // p stores the memory address of x
*p = 10; // x is now 10

int age = 26;
std::cout<< &age; //address of age is 0x7ffe2d7c3fbc

Comments