c++ - Do the addresses of variables, declared just after each other, precede each other? -
i learning c++ pointers , have following question.
when declare example 3 variables this:
int = 0, b = 1, c = 2;
will there variable have addresses precede each other... when address of a
ends, address of b
start immediately?
additionally, please provide me links of tutorials or books can learn how computer works memory (bit, byte...), because not quite understand how computer, variables , data work , can't useful link anywhere.
thanks in advance :)
it depends upon compiler how assign address's variable.
in case address's might sequential or might not be.
you can verify code :
#include"iostream" using namespace std; int main() { int = 0, b = 1, c = 2; cout<<"address of : "<<&a<<endl<<"address of b : "<<&b<<endl<<"address of c : "<<&c<<endl; return 0; }
so if need play around address of variable, take pointer of type , use pointer access or change variable.
example :
int *p_a = &a; int *p_b = &b; int *p_c = &c;
Comments
Post a Comment