Bill Potter wrote on 04/08/04 :[color=blue]
> I am a learning programmer in C and i want to know why some one would use
> pointers instead of going direct![/color]
What do you mean 'direct' ? Any object has an address. It's good to
know its location if you want to access it. A pointer is just another
variable that holds the address of an object. It's useful in many
cases, for example if you want to 'pass' an array to a function.
Actually, there is no choice, only the address of the array is passed
into a pointer to the same type.
int a[123] -> int *param_a
char b[123] -> char *param_b
Why? Probably for an question of efficiency. It could have been
technically possible to pass a copy of the whole array, but it would
have been highly unefficient.
Note that pointers are not a C-feature. They belong to most
architectures where some registers are designed to hold an address, and
to reach the value via some indirection :
[ES:DI]
(A6)
etc.
The C 'sin' is to not hide this feature. Some other languages use
different syntaxes to act as if the pointers were not existing,
providing an extra abstraction layer. Is it good or not is debatable. I
like C and its pointers, and I see no reason to use another language
for now.
--
Emmanuel
The C-FAQ:
http://www.eskimo.com/~scs/C-faq/faq.html
"C is a sharp tool"