3 ms·
My favorite pointer trick is a simple one. I learned it when I had to implement it (in 64-bit) in a C compiler. Simply, you can subtract pointers. Let's say yo
by CountHackulus 16y ago
My favorite pointer trick is a simple one. I learned it when I had to implement it (in 64-bit) in a C compiler.
Simply, you can subtract pointers. Let's say you're walking a string from the front and from the back at the same time, and want to find the length of the substring. Well, you don't have to use indeces, just do this:
int len = back_ptr - front_ptr;
You'd be surprised how often this crops up when you're using lots of pointer tricks.