When you create any variables statically, they are allocated on the stack? eg: int someInteger = 5;
When you create any variables dynamically, they are allocated on the heap? eg: int someInteger = new int(5);
Q1) Now, these two memory blocks are at OPPOSITE ends of memory aren't they?
Q2) Is it possible that they could cross over?
Q3) Does the OS prevent this from happening?
Q4) It doesn't happen in Java because everything is a "pointer" (reference to be strictly correct?) isn't it? So everything's on the heap? Nah, think I got that assumption wrong...?!
As a side thing, I'm confused about this in C++...
int myArray[100]; ?//array of 100 integers
int* myArray[100]; //array of 100 integer-pointers
int *myArray[100]; //a pointer to an array of 100 integers, but isn't an array essentially a pointer anyway in C++?
Q5) How do I go abouts accessing the memory locations in the 3rd scenario? I just get segmentation faults if I try to say make myArray[0] = 0:no:: Unless, Ahhh, the 3rd scenario is actually just an array of integer-pointers? Because in C++, these mean the same:
int* someInteger = 5;
int * someInteger = 5;
int *someInteger = 5;
Question
fault
When you create any variables statically, they are allocated on the stack? eg: int someInteger = 5;
When you create any variables dynamically, they are allocated on the heap? eg: int someInteger = new int(5);
Q1) Now, these two memory blocks are at OPPOSITE ends of memory aren't they?
Q2) Is it possible that they could cross over?
Q3) Does the OS prevent this from happening?
Q4) It doesn't happen in Java because everything is a "pointer" (reference to be strictly correct?) isn't it? So everything's on the heap? Nah, think I got that assumption wrong...?!
As a side thing, I'm confused about this in C++...
Q5) How do I go abouts accessing the memory locations in the 3rd scenario? I just get segmentation faults if I try to say make myArray[0] = 0:no:: Unless, Ahhh, the 3rd scenario is actually just an array of integer-pointers? Because in C++, these mean the same:
Link to comment
Share on other sites
20 answers to this question
Recommended Posts