Output include using namespace std int main int Ptr1 int pt

Output? #include using namespace std; int main () {int *Ptr1; int *ptr2; int **pptr; int a[8] {1, 2, 3, 4, 5, 6, 7, 8); Ptr1 = a; cout

Solution

Hi, I have commented every line of code, please go through those comments to unerstand:

#include <iostream>
using namespace std;

int main(){
  
   int *ptr1;
   int *ptr2;

   int **pptr;

   int a[8] = {1,2,3,4,5,6,7,8};

   ptr1 = a; // pointing first elelemnt (base address)of array \'a\'

   cout<<*ptr1; // output: 1 [first element of \'a\']

   ptr1 += 2; // incrementing by 2, now pointing 3rd element of \'a\' i.e. 3
   cout<<*ptr1; // Output: 3
   ptr2 = ptr1; // ptr2 pointing to third element of \'a\'
   ptr2 += 3; // incrementing by 3, now pointing 6th element of \'a\', i.e. 6

   cout<<\"\ \"; // printing new line

   cout<<*ptr2; // Output: 6
   pptr = &(ptr2); // storing address of ptr2 in pptr
   cout<<\"\ \"; // printing new line
   cout<<*(*pptr+1); // Output: 7, *pptr is address of 6, adding 1 means now pointing to next element, i.e. 7
   cout<<\"\ \"; // printing new line
   **pptr = 2; // assigning 6th element of \'a\' to 2, since ppter pointing 6th element

   for(auto i:a)
       cout<<i<<\" \";
   // output: 1 2 3 4 5 2 7 8

   return 0;
}

Final Output:

13
6
7
1 2 3 4 5 2 7 8

 Output? #include using namespace std; int main () {int *Ptr1; int *ptr2; int **pptr; int a[8] {1, 2, 3, 4, 5, 6, 7, 8); Ptr1 = a; cout SolutionHi, I have comme

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site