asked 18.3k views
2 votes
Allocate 100 integers and assign the resulting pointers to the elements of ip_arr. Initialize each integer value to -1.

1 Answer

4 votes

Answer:

#include <iostream>

using namespace std;

int main() {

int *ip_arr,n;//pointer name inp_arr and integer n to store the size.

cin>>n;//size.

for(int i=0;i<n;i++)

ip_arr[i]=-1;//assigning -1 to every element.

for(int i=0;i<n;i++)

{

cout<<ip_arr[i]<<" ";//printing every element.

}

return 0;

}

output:-

100

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

Step-by-step explanation:

I am taking input of size.You should enter 100 for 100 values which have value -1.

answered
User Mhhorizon
by
7.3k points