Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Initializing pointer to array c++

I am new to C++. Please see the following code:

//sample1
int arr[2] = { 11, 22 };
int(*t)[2];
t = &arr;
cout << *t[0] << "\n";
cout << *t[1] << "\n";
//sample2
int arr2[2];
arr2[0] = { 33 };
arr2[1] = { 44 };
int(*t2)[2];
t2 = &arr2;
cout << *t2[0] << "\n";
cout << *t2[1] << "\n";
//sample3
int arr3[2];
arr3[0] = { 55 };
arr3[2] = { 66 };
int(*t3)[2];
t3 = &arr3;
cout << *t3[0] << "\n";
cout << *t3[1] << "\n";

// output

11
-858993460
33
-858993460
55
66

Can anyone tell me how to initializing a pointer to array?Sample3 is out of my understanding.

Answer*

Draft saved
Draft discarded
Cancel

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /