Answer the question
In order to leave comments, you need to log in
How to clear a pointer - C++?
Pointer
double **p = 0;
Complete the following tasks (decisions can be made inside the main function).
Create the structure shown in the figure.
Print the number in the square on the screen. After that delete all dynamic objects.
double **p = new double*; // динамическое выделение памяти под указатель double
double value = 2;
double *index = new double; // динамическое выделение памяти под объект типа double
index = &value; // Передаем указателю адрес переменной value;
p = &index; // передаем указателю адрес указателя index;
cout << "Адрес value: " << &value << "\n";
cout << "В index хранится адрес value: " << index << "\n";
cout << "Адрес index: " << &index << "\n";
cout << "В p хранится адрес index: " << p << "\n";
cout << "В *p хранится значение index: " << *p << "\n";
cout << "В **p хранится значение value: " << **p << "\n";
return 0;
Answer the question
In order to leave comments, you need to log in
int main( void ) {
double **p = 0;
*( *( p = new double* ) = new double ) = 2;
cout << **p << endl;
delete *p;
delete p;
}
stackoverflow.com/questions/13223399/deleting-a-po... is this?
Described the solution:
myPointer = new int;
delete myPointer;
myPointer = NULL;
Therapyx Thank you very much! In the course of my experiments, I came to this solution.
void oneCell {
double **p = new double*; // динамическое выделение памяти под указатель double
double value = 2;
double *index = new double; // динамическое выделение памяти под объект типа double
index = &value; // Передаем указателю адрес переменной value;
p = &index; // передаем указателю адрес указателя index;
cout << "Адрес value: " << &value << "\n";
cout << "В index хранится адрес value: " << index << "\n";
cout << "Адрес index: " << &index << "\n";
cout << "В p хранится адрес index: " << p << "\n";
cout << "В *p хранится значение index: " << *p << "\n";
cout << "В **p хранится значение value: " << **p << "\n";
p = new double*;
index = new double;
delete p;
delete index;
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question