Found 7346 Articles for C++

What is Bitwise XOR in C++?

Daniol Thomas
Updated on 11-Feb-2020 07:23:15

221 Views

The bitwise exclusive OR operator (^) compares every bit of} its 1st operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. Both operands to the bitwise exclusive OR operator must be of integral types. For example,Example#include   using namespace std;   int main() {      unsigned short a = 0x5555;      // pattern 0101 ...      unsigned short b = 0xFFFF;      // pattern 1111 ...      cout  

What is overloading a unary operator in C++?

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

238 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 are primitive data type in C++?

Fendadis John
Updated on 11-Feb-2020 07:19:29

4K+ Views

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

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

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

11K+ 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++

V Jyothi
Updated on 11-Feb-2020 07:12:45

200 Views

The operator keyword declares a function specifying what operator-symbol means that once applied to instances of a class. this gives the operator more than one meaning, or "overloads" it. 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 ... Read More

Overload unary minus operator in C++?

Nikitha N
Updated on 11-Feb-2020 07:09:40

6K+ Views

The operator keyword declares a function specifying what operator-symbol means when applied to instances of a class. This gives the operator more than one meaning, or "overloads" it. 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 ... Read More

Whitespace in C++

V Jyothi
Updated on 11-Feb-2020 06:48:24

7K+ Views

Whitespace is a term that refers to characters that are used for formatting purposes. In C++, this refers primarily to spaces, tabs, and (sometimes) newlines. The C++ compiler generally ignores whitespace, with a few minor exceptions. For example, all the 4 lines below mean the same thing −cout

How to convert a Python for loop to while loop?

Pythonista
Updated on 11-Feb-2020 06:47:06

8K+ Views

Unlike while loop, for loop in Python doesn't need a counting variable to keep count of number of iterations. Hence, to convert a for loop into equivalent while loop, this fact must be taken into consideration.Following is a simple for loop that traverses over a rangefor x in range(5):      print (x) To convert into a while loop, we initialize a counting variable to 0 before the loop begins and increment it by 1 in every iteration as long as it is less than 5x=0 while x

Print Hello World without semicolon in C++

Syed Javed
Updated on 11-Feb-2020 06:57:23

968 Views

There are multiple ways to write a C++ program without semicolons. Note that doing this is very bad practice and should never be used in real code. This is presented just as informational content. The easiest way to write a C++ Program without Semicolons is using if statements. Almost all statements in C++ can be treated as expressions. So, if we place the statement inside an if statement with a blank pair of parentheses, we don’t have to end it with a semicolon anymore. ExampleLive Demo#include int main() {    if (std::cout > N) {}       if (std::cout

Putting semicolons after while and if statements in C++

Moumita
Updated on 11-Feb-2020 06:55:05

2K+ Views

When you have a statement like −while (expression);the while loop runs no matter if the expression is true or not. However, if you put −if (expression);the statement runs no matter if the expression is true or not. This is because the syntax for if and while is −if () // or while () So the is only executed if the evaluates to true. In while, it will enter an infinite loop.So the question what it executes. If there are not braces {} then the next statement is terminated by; even if that statement is EMPTY. Note ... Read More

Advertisements