I'm sorry if this has been answered elsewhere, but I couldn't find it easily so figured I'd ask to see if I could get any deeper insight into it rather than a textbook explanation.
I'm now to a part in my book where I'm going to be implementing my own vector class. I know the STL has one, but the book insists on doing it to explore the (almost) extreme low levels of the language, as well as using it for an introduction to pointers. Ok, so here's my question.
int x = 5; //arbitrary value of 5
int* xPtr = &x; // so now I have xPtr of type int* pointing to the memory address of x
// Here's my question though. In the book when it was explaining why you can't switch
// pointer types without explicitly doing so, it used an example like this (the comments are mine)
cout << "The size of char is " << sizeof(char) << " " << sizeof('a') << endl; // ok, I can understand this
cout << "The size of int is " << sizeof(int) << " " << sizeof(2+2) << endl; // and this
int* p = 0; // ?? Is it referring to the very first part in my computer's memory? I've no idea
cout << "The size of int* is " << sizeof(int*) << " " << sizeof(p) << endl; // same size as an int
Also, the sizes it returns for a char or bool is 1, int and long is 4, and double is 8. Is that the same as saying "a char or boolean refers to 1 4 bit chunk of memory" and so on? And that unfortunately leads my mind to another topic. If my computer is a 64 bit architecture with a 64 bit OS, how come an int can't hold a value in the range of -2^64 : 2^64 - 1?
Sorry if that's a lot of rambling.
This post has been edited by erewnoh: 11 March 2009 - 07:46 PM

New Topic/Question
Reply




MultiQuote





|