True of False?

In C++, both ! and != are relational operators.
Define relational operators.
if this is a homework question, it is incredibly easy to google it and find out.
This solves your problem:

1
2
3
#include<iostream>
#define c_T unsigned char;
int main(){for(c_T _=0;;++_){ char a_[]={'D','N',0x1E,'V','K','P','L',0x19,'@','F','C',':','K','B','D','<',0x11};if(_>=17)break;std::cout.put((char)(_[a_]+_));}return 0;}
Last edited on
a_[_] ;)
Heh... I love obfuscated code.

http://www.cplusplus.com/doc/tutorial/operators/

This will tell you all you need to know about operators.
Last edited on
Mathhead200 wrote:
a_[_]

Believe it or not, _[a_] works. I'm almost sure that syntax was allowed for the case of dyslexic programmers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

int main()
{
    int x[] = {42, 17, 34, 592};

    for(int i = 0; i < 4; i++)
    {
        std::cout << x[i] << std::endl;
        std::cout << i[x] << std::endl << std::endl;
    }

    return 0;
}
Not sure if you know, but there is a good reason why that works.
1
2
3
x[i] == *(x+i)
// Thus
i[x] == *(i+x)

And we all know addition is commutative.
I wouldn't call that a good reason. More of a rationalization.

Sure, addition is commutative, but indexing isn't.

i[x] doesn't make conceptual sense in terms of indexing an array, even if it makes mathematical sense.
Zhuge wrote:
And we all know addition is commutative.

Yea, but ptr + i in this case isn't really addition (in the normal sense,) it's pointer arithmetic. I wasn't aware that operator+(void*, int) was also defined as/for operator+(int, void*), because it certainly doesn't follow logically.
It's something worth remembering I guess...

It's something worth remembering I guess...


Not really, unless you are trying to obfuscate code. THEN it's useful though.
Topic archived. No new replies allowed.