i'm new to programming. I wanted to create two integer arrays which are adjacent in memory. i had written the following code, but i'm getting segmentation fault when i run it. Code: #include<iostream> using namespace std; void printarray(int* a,int size) { for(int i=0;i<size;i++) cout<<a[i]<<endl; } int main() { int a[3]={0,1,2,}; //the first array int* pa; pa = &(a[2]); pa++; int* b = pa; //the second array for(int i=0;i<3;i++) { b[i]=i+2; } printarray(a,3); printarray(b,3); } any help would be greatly appreciated..thanks
Why do you want them to be adjacent in memory, what problem do you think this will solve? If you want them adjacent, why not just allocate one array that will hold the items for both?