By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,847 Members | 2,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,847 IT Pros & Developers. It's quick & easy.

question about pointers???

P: 23
is it possible to declare any array of constant pointers? why?
Sep 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: 23
You CAN make just about anything a constant. But if you did that, you would have to initialize the pointers when you created them, and could never dynamically allocate more memory.

This could be useful, though, because a pointer uses much less memory (potentially) than the object to which it points. That way, you could save yourself (potentially, again) A LOT of over head from passing arguments to functions.

For instance, if you created a user-defined object that took up, say, 100 bytes of memory (maybe it's a class that contains 100 chars). To pass that to a function would require an entire copy of the class, and the time it took to create the copy.

But, the pointer to the class, since it only contains an address, might be only 1 byte, or maybe 2, or 4, depending on the system. Either way, it's considerably smaller than 100, so it would (potentially) save your program processing time to be using only pointers instead of complete objects.
Sep 30 '06 #2

100+
P: 293
D_C
A constant pointer is a reference. If you had N references, then an array of N const pointers would work wonderfully.
Sep 30 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
In embedded applications we often use constant pointers to point at specific locations of hardware registers since these generally don't move during program execution.
Sep 30 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.