Hello, I'm not much of a programmer and will probably never be, but am just curious.
Can I initialize a pointer with a constant value different than NULL? I.e. can I tell my pointer to point at one particular memory cell? It's a number so why couldn't I? I know it would be of little use in normal programming, but I thought it could be could good while programming some devices with very little memory, where one would like to control every cell.
mmasny 0 Light Poster
Recommended Answers
Jump to PostYes you can do that.
But details do vary from one compiler to another (and the kind of machine you're running on).
Jump to PostYes. That's one of the main reasons for having pointers.
Jump to Post>If so, how do I write this constant address?
Cast it to the appropriate pointer type:int *p = (int*)1;
However, it's strongly recommended that you don't do this unless you really know what you're doing.
All 9 Replies
Salem 5,265 Posting Sage
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
mmasny 0 Light Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
mmasny 0 Light Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Narue 5,707 Bad Cop Team Colleague
mmasny 0 Light Poster
Salem 5,265 Posting Sage
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.