Can i assign address to a pointer Manually like this????
can anyone explain this???
will this throw compile time error in all compilers???Code:int *ptr=0x4000;
Can i assign address to a pointer Manually like this????
can anyone explain this???
will this throw compile time error in all compilers???Code:int *ptr=0x4000;
I don't believe it results in any kind of compile-time error.
However it almost certainly wont do what you want, as any attempt to use that pointer will probably result in a run-time error.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Compilers are required to issue a diagnostic for that code. An integer other than a literal zero can't be assigned to a pointer (which means an integer can't be used to initialize a pointer). After issuing a diagnostic, a compiler is free to continue compiling, but it is not required to.
You can use a cast to convert an integer to a pointer, but of course the results aren't guaranteed to be anything useful.
So how do you assign a specific address to a pointer?
What I mean is If I know that a particular piece of hardware writes to a specific memory address and I want to read it...
cast it.
Code:int *ptr = (int*)0x4000;
sweet. Thanks