Home

Search IconIcon to open search

C tricks

C (language)

You can do arithmetic with chars. So to convert number n to char you can do

1
'0' + n

You can also do that with the results of logical operations (if you want to annoy somebody):

1
123 + (n > 0)

You can detect an operating system on which the code is executed:

1
2
3
4
5
6
#ifdef __linux__
// Some linux-specific code
#endif
#ifdef __APPLE__
// Some Apple-specific code
#endif