What will the contents of the a array after the following st

What will the contents of the a array after the following statements are executed?

# define N 10

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

int *p = &a[0], *q = &a[N-1], temp;

while (p

temp = *p;

*p++ = *q;

*q-- = temp; }

Solution

Program :

#include <iostream>
# define N 10
using namespace std;
int main() {
int a[N] = {1,2,3,4,5,6,7,8,9,10};
int *p = &a[0], *q = &a[N-1], temp;
while(p)
{
temp = *p;
*p++ = *q;
*q-- = temp;
}
cout << \"The content of array after execution of above statements is a[N] = \" <<a[N] << endl;
}

Output:

The content of array after execution of above statements is a[N] = 0

What will the contents of the a array after the following statements are executed? # define N 10 int a[N] = {1,2,3,4,5,6,7,8,9,10}; int *p = &a[0], *q = &am

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site