Answer the question
In order to leave comments, you need to log in
Pointers. How to create a similar design (in the application)?
Pointer double **p = 0;
It is necessary to create a construction of the form:
The length of the array is entered previously from the keyboard. Zero out all array elements. Put the number 2 in the first and last elements and print the array to the screen. Delete all dynamic objects.
My code:
double **p = 0;
int size = 0;
cout << "Введите размер массива: ";
size = inputInt();
cout << "Размер массива: " << size << endl;
if (size <= 1) {
size = 1;
}
p = new double*[size];
for (int i = 0; i < size;i++) {
p[i] = new double(0);
cout << p[i] << "\t";
}
**p = 2;
*p[size-1] = 2;
for (int i = 0; i < size;i++) {
cout << *p[i] << "\t";
}
for (int i = 0; i < size;i++) {
delete[] p[i];
}
delete[] p;
Answer the question
In order to leave comments, you need to log in
p -> x -> []
double **p;
p = new double *;
*p = new double[size];
*p[i] = ...
Yes it is. Why do you need a pointer to a pointer in this lab?
How to do the first drawing
p = new (double*)[1];
p[0] = new double[size];
#include <iostream>
using namespace std;
int main()
{
double **p = 0;
p = new double *;
int size;
cout << "Input size: ";
cin >> size;
*p = new double[size];
for (int i = 0; i < size; i++)
*(*p + i) = 0;
**p = *(*p + size - 1) = 2;
cout << "size: " << size << endl;
for (int i = 0; i < size; i++)
cout << *(*p + i) << " ";
cout << endl;
delete [] *p;
delete p;
p = 0;
return 0;
}
[[email protected] cpp]$ .iso++ t.cpp -o t
[[email protected] cpp]$ ./t
Input size: 10
size: 10
2 0 0 0 0 0 0 0 0 2
[[email protected] cpp]$
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question