Found 7197 Articles for C++

What is Bitwise OR in C++?

Akansha Kumari
Updated on 17-Apr-2025 18:46:04

848 Views

Bitwise operators are the operators that are used to perform operations on bits of a binary representation of a number.Bitwise OR (|) Operator OR Operator (|) is one of the types of bitwise operators, which compares each bit of the first operand to the corresponding bit of the second operand and returns 1 if at least one of the bits is 1; else 0 if both bits are 0. You can think of it as similar to addition in decimal, like 0 + 0 = 0, and all other combinations result in 1. But this ... Read More

What is Bitwise AND in C++?

Akansha Kumari
Updated on 21-Apr-2025 12:17:30

713 Views

The Bitwise AND (&) Operator is one of the types of bitwise operators, which perform operations on bits of a binary representation. The Bitwise AND (&) compares each bit of the first operand to the corresponding bit of the second operand and returns 1 if both bits are 1, else returns 0 if either or both bits are 0.You can think of it as similar to multiplication in decimal, like 1 * 1 = 1, and all other combinations result in 0. But ensure that both operands are of integral data types (as it works with binary representations) like int, ... Read More

What are fundamental data types in C++ programming?

Rama Giri
Updated on 11-Feb-2020 07:28:40

2K+ Views

A fundamental or primitive type is a data type where the values that it can represent have a very simple nature (a number, a character or a truth-value); the primitive types are the most basic building blocks for any programming language and are the base for more complex data types.C++ has the following primitive data types −S.NoTypeDescription1boolStores either value true or false.2charTypically a single octet (one byte). This is an integer type.3intThe most natural size of an integer for the machine.4floatA single-precision floating point value.5doubleA double-precision floating point value.6voidRepresents the absence of type.Read More

What is Bitwise XOR in C++?

Akansha Kumari
Updated on 18-Apr-2025 19:39:12

472 Views

The XOR operator(^), also known as "exclusive OR", is one of the types of bitwise operators, which compares each bit of the first operand to the corresponding bit of the second operand and returns 1 if both bits are different, else returns 0 if both are the same. This only works with integral data types like int, char, short, long, and unsigned int, etc, and cannot be directly used with float, double, string, and class/struct objects, etc. Syntax Here is the following syntax of Bitwise XOR. result = operand1 ^ operand2; Where operand1 and operand2 are the integral types (like ... Read More

What is overloading a unary operator in C++?

Krantik Chavan
Updated on 11-Feb-2020 07:21:47

376 Views

The single operators operate on one quantity and following are the samples of single operators − - The increment ( ) and decrement (--) operators. The compiler distinguishes between the different meanings of an operator by examining the types of its operands.The unary operators operate on a single operand and following are the examples of Unary operators −The increment (++) and decrement (--) operators.The unary minus (-) operator.The logical not (!) operator.The unary operators operate on the object for which they were called and normally, this operator appears on the left side of the object, as in !obj, -obj, and ... Read More

What does 'using namespace std' mean in C++?

Moumita
Updated on 30-Jul-2019 22:30:21

12K+ Views

Consider a situation, when we have two persons with the same name, Piyush, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in a different area or their mother’s or father’s name, etc.The same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of ... Read More

Overloading unary operators + in C++

Akansha Kumari
Updated on 28-Apr-2025 19:03:29

359 Views

The unary operators are operators that operate only on a single operand. There are mainly thirteen unary operators in C++, for example, ++, !, ~, typeof, delete, etc.Overloading a unary operator means setting a customized behaviour for the unary operators for the objects of a class. which means you can define how an operator will work when applied to instances of a class instead of using its default behavior. This operator is generally used on the left side of the object, as in +obj, !obj, -obj, and ++obj, but can also be used as a postfix like obj++ or obj--. So, ... Read More

Overload unary minus operator in C++?

Akansha Kumari
Updated on 02-May-2025 18:48:25

8K+ Views

Unary operators are operators that operate only on a single operand (unlike binary operators, which operate on two operands). There are mainly thirteen unary operators that exist in C++, for example, ++, !, ~, typeof, delete, etc. Overloading Unary Minus Operator Overloading a unary operator means defining a custom behavior for the unary operators while applying it to objects of a class. which means you can define how an operator will work when applied to instances of a class instead of using its default behavior. This operator is normally used on the left side of the object, as in +obj, ... Read More

Whitespace in C++

Akansha Kumari
Updated on 22-Apr-2025 17:20:57

8K+ Views

The term Whitespace in C++ refers to the characters used for formatting, like creating spaces, tabs, and newlines. These are usually invisible in the source code output (meaning they don't appear in the actual program output); they just help to format the code and improve readability. Types of whitespace characters Here are the following four common types of whitespace characters mostly used in C++. Space (' ') Tab ('\t') Newline ('') Carriage return ('\r') Space (' ') It's a most basic whitespace ... Read More

How to convert a Python for loop to while loop?

Akansha Kumari
Updated on 22-Apr-2025 17:21:10

11K+ Views

Converting a for loop to a while loop in Python means rewriting the loop logic in a different way to perform the same task.While loop gives better control over conditions and is also useful for cases when the number of iterations is not fixed and depends on runtime values. Therefore, sometimes while is preferred over a for loop when the loop's continuation depends on dynamic conditions. For Loop Code Here is the following simple for loop that traverses over a range. for x in range(5): print(x) Output 0 1 2 3 4 To convert ... Read More

Advertisements