C++ Articles - Page 710 of 719

Overloading unary operators + in C++

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

372 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

Print Hello World without semicolon in C++

Alshifa Hasnain
Updated on 07-Apr-2025 12:11:49

2K+ Views

In this article, we will learn to print Hello World without a semicolon in C++. The semicolon (;) is used to terminate statements. The above can be achieved by using control structures like loops, conditionals, or function calls. Different Approaches There are multiple ways to write a C++ program without semicolons − Using if Statements Using a while Loop Using Switch Statement Note: Doing this is a very bad practice and should never be used in real code. This is presented just as informational content. ... Read More

Putting semicolons after while and if statements in C++

Akansha Kumari
Updated on 23-Apr-2025 19:19:08

3K+ Views

In C++, a semicolon(;) indicates the end of a statement in code, or we can say it terminates the statement. When you use a semicolon just after an if or while statement, it creates an empty statement, which executes nothing. Semicolon with If Statement In C++, the if statement is a conditional statement that runs only if the condition is true, where {} braces are used to write the condition inside them. But if you use a semicolon just after the if statement, it will still check the condition, but it controls just an empty operation; therefore, nothing will happen ... Read More

Unary operators in C++

Rama Giri
Updated on 11-Feb-2020 06:53:36

360 Views

Unary operator are operators that act upon a single operand to produce a new value. The unary operators are as follows −Indirection operator (*) - It operates on a pointer variable, and returns an l-value equivalent to the value at the pointer address. This is called "dereferencing" the pointer.Address-of operator (&) - The unary address-of operator (&) takes the address of its operand. The operand of the address-of operator can be either a function designator or an l-value that designates an object that is not a bit field and is not declared with the register storage-class specifier.Unary plus operator (+) - ... Read More

Reserved keywords in C++?

Arjun Thakur
Updated on 19-Jun-2020 05:31:50

10K+ Views

A reserved word is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a reserved word may have no meaning.There are a total of 95 reserved words in C++. The reserved words of C++ may be conveniently placed into several groups. In the first group, we put those that were also present in the C programming language and have been carried over into C++. There are 32 of these. There are another 30 reserved words that were not in ... Read More

Trigraphs in C++

Akansha Kumari
Updated on 22-Apr-2025 18:50:06

334 Views

Trigraphs in C++ are special three-character sequences that represent a certain single character, which may not be available on some keyboards or systems. Previously, the ISO-646 character set did not have all the characters of the C syntax; therefore, some systems with their keyboard and display faced problems while dealing with those few characters.So the trigraphs have been introduced, which start with two question marks (??) and are further followed by a third character, which the compiler considers as a particular equivalent single-character. Trigraphs Table in C++ There are a total of nine trigraphs available in C++; here is the ... Read More

C++ Operators with Precedence and Associativity

Akansha Kumari
Updated on 29-May-2025 15:41:53

4K+ Views

In C++, operator precedence and associativity both work together to define the order of evaluation in an expression. Order precedence determines which operators need to be evaluated first according to precedence, whereas associativity defines the direction of operators to be evaluated of the same precedence. Operator precedence Operator precedence refers to the order of operations to be performed in expressions when multiple operators are present; here, operators with higher precedence (priority) are calculated first. For example: int x = 5 + 17 * 5; Here, according to operator precedence, multiplication has higher precedence than addition, therefore, it will first get ... Read More

Advertisements