Reputation: 3
I am experimenting with pointers in C programming for a project and was looking to get some guidance on whether there are other ways to initialize a pointer constant to the memory address 0x0001a000.
The following was my approach:
volatile int *firstAddress = (volatile int *)0x0001a000;
printf("First Memory address is: %p\n", firstAddress);
Are there shorter ways to initialize the above in C programming?
Upvotes: 0
Views: 52
Reputation: 224677
This is exactly how you would initialize such a constant, however the results are very implementation specific.
If the given address isn't one explicitly documented as valid, you'll likely invoke undefined behavior.
You also can't really make it any more concise than this. Conversions between integers and pointers requires a cast.
Upvotes: 1