I have a bit that I am toggling in my program, and was wondering if I can do this:
char *toggle = // some address;
*toggle = 0; // initially
// if(something)
// *toggle = 1;
// other code that continues to toggle under certain conditions...
But dereferencing a char* treats the value like a char, nothing more and nothing less. So I was wondering if it is a valid method of storing the 1 and 0 (which are integers)?
Yes, that’s a completely valid method.
charcan be treated like an integerin most cases– and as such you can also do arithmetic on variables of typechar.