Pointer Arithmetic Operations #include using namespace std; int main() = int * p; int a [10]; int index; for
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Pointer Arithmetic Operations #include using namespace std; int main() = int * p; int a [10]; int index; for
Pointer Arithmetic Operations #include <iostream> using namespace std; int main() = int * p; int a [10]; int index; for (index = 0; index <10; index++) a[index] index; p = a; // After this assignment, p points to the same memory location that a points to. So, p[0l, pil), p19) refer to the indexed variables a[0]... a[9]. //int *p2; a = p2; // is illegal for (index = 0; index < 10; index++) cout << p[index] < " "; cout << endl; for (index = 0; index <10; index++) *(p+index) =* (p+index) +1; // same as: p[index] = p[index] + 1; for (index = 0; index < 10; index++) cout << a[index] «""; // same as: cout << * (p+index) < " "; and cout << p[index] << " "; cout << endl; return 0; 1
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!