I am working on a C program that I did not write and integrating it with my C++ code. This C program has a character array and usage putc function to print the content of it. Like this:
printf("%c\n","01"[b[i]]);
This is a bit array and can have either ASCII 0 or ASCII 1 (NOT ASCII 48 and 49 PLEASE NOTE). This command prints “0” and “1” perfectly. However, I did not understand the use of “01” in the putc command. I can also print the contents like this:
printf("%d\n",b[i]);
Hence I was just curious. Thanks.
Newbie
Nasty way of doing the work, but whoever wrote this was using the contents of b as an array dereference into the string, “01”:
your array, b, contains 0s and 1s, and the author wanted a way to quickly turn those into ‘0’s and ‘1’s. He could, just as easily have done:
But that’s another criminal behavior. =]