Let's have a following code:
#include <iostream>
struct TStruct{
int x;
int y;
int * ptr;
TStruct( void ) : x( 0 ), y( 0 ), ptr( nullptr ) { }
};
int main(){
TStruct arr[100];
TStruct * arr2 = new TStruct[200];
// some code working with these arrays
for( int i = 0; i < 100; i ++ )
if( arr[i] . ptr != nullptr )
delete [] arr[i] . ptr;
for( int i = 0; i < 200; i ++ )
if( arr2[i] . ptr != nullptr )
delete [] arr2[i] . ptr;
delete [] arr2;
return 0;
}
How does initialization of both of these arrays - static and dynamic - works? Are they automatically initialized by TStruct constructor or do I have to initialize them manually by looping both of them and setting values for each TStruct member?
deleteon a null pointer.deletewithout any issues?