assigning hexadecimal value


i wanted to ask if there is a way to assign a hexa decimal value to a variable directly in c++ ???

waiting for replies
Who is Participating?
alkisgConnect With a Mentor Commented:
Sorry, you also need a typecast:
int *a = (int *)0x1234;
int a = 0x1234;
fatimaoAuthor Commented:
yup thanks its working! but we cant assign the hexa-decimal address ... right?
like &a = 0x1234

Is there a way to move a variable (allocate variable) adress of your own choice?

 best regards
No, you can't declare a variable to occupy a specific memory address.
In Pascal you can do
  a: byte absolute $A000:0;
but not in C.

But that's what pointers are for:
int *a = 0x1234;
This is a pointer to the memory with address 0x1234.
Then you can do
*a = 5;

This will result to
RAM[0x1234] = 5
fatimaoAuthor Commented:
thanx for a nice reply but ...
i tried it in visual studios and this line "int *a = 0x1234;" gives error "cannot convert from const int to int *"

so we can't even assign hexa decimal address to a pointer in c?

please clear the confusion
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.