Found 33676 Articles for Programming

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 use continue statement in Python loop?

Pythonista
Updated on 27-Feb-2020 05:24:32

120 Views

The loop control statement continue abandons the pending statements in current iteration of the looping block and starts next iteration. The continue statement appears in a conditional block inside loopExamplex=0 while x

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

How to stop an infinite loop safely in Python?

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

432 Views

Infinite loop is the one that doesn't stop on its own. It happens when the looping condition continues to remain true forever. In such a case, the loop must be forcibly stopped by pressing ctrl-C to generate keyboard interrupt

How to prevent loops going into infinite mode in Python?

Gireesha Devara
Updated on 23-Aug-2023 19:02:26

3K+ Views

In python the while loop needs to be controlled by making some provision inside the body of the loop to drive the condition mentioned in the beginning to false. This is usually done by keeping count of iterations. If the while loop condition never evaluates to False, then we will have an infinite loop, which is a loop that never stops automatically, in this case we need to interrupt externally. count=0 while condition: stmt1 stmt2 . . count=count+1 Example Let’s take an example and ... 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

347 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

Advertisements