Reputation: 51
Hi I am puzzled and don’t know what this test condition mean in this loop.
j<+i
Can someone please explain how it works and how to read it step by step?
for(int i = 0; i<5; i++)
for(int j = 0; j<+i; j++)
Upvotes: 1
Views: 94
Reputation: 234715
The unary plus operator +
is a no-op with the exception that the expression +a
is at least as wide as an int
.
So in your case it is a no-op, but it can make a difference on the odd occasion:
#include <iostream>
void foo(int a){
std::cout << "pay me a bonus\n";
}
void foo(char a){
std::cout << "format my hard disk\n";
}
int main()
{
char a = '0';
foo(a);
foo(+a);
}
Upvotes: 4
Reputation: 9682
The '+' isn't needed within this context (it's a unary + operator, but no one ever uses it because it's mostly pointless). i == +i.
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < i; j++)
{
}
}
Upvotes: 1