Code: Show/Hide int strlen(char* s)
{ int len = 0; for (int x = 0; s[x]; ++x) ++len; return len; } |
Code: Show/Hide int strlen(char *s)
{ if (*s) return strlen(s+1) + 1; else return 0; } |
Code: Show/Hide printf("%c", 1["dr brain"]+1); |
Code: Show/Hide int main() { return printf("dr brain won #2 \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b \b\n") } |
Code: Show/Hide int main() { if (!pthread_create(malloc(sizeof(pthread_t)), NULL, exit, printf("dr brain won #2\n") + 100 - 16)) {while(1){}} } |
Samapico wrote: |
I'd do something like
if ( exit( printf("dr brain won #2")+85 ) ) { } But exit returns a void, so it doesn't compile either |
Code: Show/Hide #include <stdio.h>
int i(int i, int ii) { return ii == i; } int main() { int (*ii)(int, int) = i; int i = 0; if (i++ == ++i) printf("%i", i + 1); else printf("%i", i); if (ii(i++, ++i)) printf("%i", i + 1); else printf("%i", i); if (ii(++i, i)) printf("%i", i + 1); else printf("%i", i); return 0; } |
Quote: |
So basically, the value returned by the whole expression is the result of the part after the last comma? |
Code: Show/Hide #include <stdio.h>
struct EqualInt { int i; EqualInt operator++() { ++i; return *this; } // preincrement EqualInt operator++(int) { EqualInt copy = *this; ++i; return copy; } // post increment }; bool operator==(const EqualInt &left, const EqualInt &right) { return left.i == right.i; } int main() { EqualInt a; int i = 0; if (i++ == ++i) printf("true\n"); else printf("false\n"); if (a++ == ++a) printf("true\n"); else printf("false\n"); return 0; } |
Code: Show/Hide void swap(int* a, int* b)
{ int temp = *a; *a = *b; *b = temp; } |
Code: Show/Hide void swap(int* a, int* b) { *a ^= (*b ^= (*a ^= *b)); } |
Code: Show/Hide void swap(int* a, int* b) { #define lol ; int temp = *a lol *a = *b lol *b = temp lol } |
Code: Show/Hide void swap(int* a, int* b) { a==b ? b = a : *a ^= (*b ^= (*a ^= *b)); } |
Code: Show/Hide ..\main.c:6: warning: use of conditional expressions as lvalues is deprecated
..\main.c:6: error: invalid operands to binary ^ ..\main.c:6: error: invalid operands to binary ^ ..\main.c:6: error: invalid lvalue in assignment |
Code: Show/Hide void swap(int* a, int* b) { a != b && (*a ^= (*b ^= (*a ^= *b))); } |