Pointers in C (2010)
boredzo.org
Pointers in C (2010)
1–10 of 113 posts
Re: Pointers in C (2010)
#2Re: Pointers in C (2010)
#3I always wonder what makes pointers so difficult for some. So far I have always been able to explain it to people by drawing a linear memory space and then showing how different types are allocated. It seems to me that pointers are one the easier concepts in programming.
Re: Pointers in C (2010)
#4It claims that, given a declaration
int array[] = { 45, 67, 89 };
the expressions "array", "&array", and "&array[0]" are all equivalent. They are not. "&array" and "&array[0]" both refer to the same memory location, but they're of different types.In the next section:
"By the way, though sizeof(void) is illegal, void pointers are incremented or decremented by 1 byte."
Arithmetic on void pointers is a gcc-specific extension (also supported by some other compilers). It's a constraint violation in standard C.
I don't think this is the "best" article on pointers in C.
I usually recommend section 6 of the comp.lang.c FAQ, http://www.c-faq.com/
Re: Pointers in C (2010)
#5In particular, it supplies a useful algorithm for decoding all pointer declarations such as functions that return function pointers.
Re: Pointers in C (2010)
#6I always wonder what makes pointers so difficult for some. So far I have always been able to explain it to people by drawing a linear memory space and then showing how different types are allocated. It seems to me that pointers are one the easier concepts in programming.
While I agree that a simple figure does a good job at explaining what a pointer is, it takes quite a bit longer to develop an intuitive sense of how to effectively work with pointers. In that case it's the more examples, the better.
Re: Pointers in C (2010)
#7Re: Pointers in C (2010)
#8Earlier quoted context omitted.
While I agree that a simple figure does a good job at explaining what a pointer is, it takes quite a bit longer to develop an intuitive sense of how to effectively work with pointers. In that case it's the more examples, the better.
The syntax gets funky, as well, especially in modern eyes.
Re: Pointers in C (2010)
#9Re: Pointers in C (2010)
#10Earlier quoted context omitted.
The syntax gets funky, as well, especially in modern eyes.
To add another reason they’re difficult: many non-trivial uses of pointers are in particularly hairy situations, such as navigating complex data structures.