for the following:
( a != b ) ? cout<<"not equal" : cout<<"equal";
suppose I don't care if it's equal, how can I use the above statement by substituting cout<<"equal"
with a no-op.
In computer science, a NOP, no-op, or NOOP (pronounced "no op"; short for no operation) is a machine language instruction and its assembly language mnemonic, programming language statement, or computer protocol command that does nothing.
It should be noted that, when used as a macro (say, #define noop ((void)0) ), the (void) prevents it from being accidentally used as a value (like in int x = noop; ).
A no op (or no-op), for no operation , is a computer instruction that takes up a small amount of space but specifies no operation. The computer processor simply moves to the next sequential instruction. The no op is included in most assembler languages.
Last updated: April 1, 2017. In Python programming, pass is a null statement typically used as a placeholder. In contrast to a comment statement which is ignored by the Python interpreter, a pass statement is not ignored but nothing happens when it is executed. It results in No Operation (NOP).
No-operation instruction. Alternatively referred to as a do-nothing instruction, the no-operation instruction, NO-OP or NOP instruction in programming tells a program to do nothing if a conditional statement is met.
Alternatively known as a do-nothing instruction, the no-operation instruction, NO-OP or NOP instruction in programming tells a program to do nothing if a conditional statement is met. In C a semicolon ( ; ) by itself or an empty block ( {} ) is an NOP.
How does a C program executes? - GeeksforGeeks How does a C program executes? Whenever a C program file is compiled and executed, the compiler generates some files with the same name as that of the C program file but with different extensions.
The no op is included in most assembler languages. It may have a label and can serve as a placeholder for a useful instruction to be inserted later during code development. The New Hacker's Dictionary reports as a derivative meaning "A person who contributes nothing to a project, or has nothing going on upstairs, or both.
If it really is for a ternary operator that doesn't need a second action, the best option would be to replace it for an if:
if (a!=b) cout << "not equal";
it will smell a lot less.
Simple: I would code it as
if (a != b)
cout << "not equal";
The ternary operator requires the two results to be of the same type. So you might also be able to get away with
(a != b) ? cout << "not equal" : cout;
because the stream operator (<<) just returns the ostream reference. That's ugly and unnecessary in my opinion though.
The following will achieve what you're looking for, however, it may not be clear to people reading your code why it works:
(a != b) && (cout << "equal");
Personally, I agree with this answer from Vinko Vrsalovic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With