You are here:

C/abt pointers

Advertisement


Question
I read in a book about pointers and them uses. What i don't understand
is why use pointers to arrays, chars, int and string? if i got an
array, why should i go ahead and decide to use a pointer to that array? when
do u think one should use a pointer to any data type? I dont' mean
passing the address of a variable to a function parameter now. ok take
alook at the example blow:

char *name[30]; and char name[30]

when do u think the pointer to the character data type should be used or when do u think it is proper to use a pointer to a data type?
instead of the cahracter array ?

Henry

Answer
When you declare a variable, the address where its value is stored is decided at compile time.
When the declare an array, its size is decided at compile time.
If you want to change the size of array when you are executing the program, it is not possible.
In these type of situations pointers help - it is used when you want dynamic memory allocation. That is allocate memory during run time.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.