vxk wrote: |
---|
pointer36[i] = *new int; |
new int
— Create new int somwhere in memory; returns ponter to newly created integer.
*new int;
— Dereference returned pointer; returns actual value,
produces undefined behavior as variable is uninitialized
pointer36[i] = *new int;
— Assigns said value to array element with index
i
This code leaks, as allocated memory never deleted and pointer to it is lost.
vxk wrote: |
---|
pointer37[i] = *new int[x]; |
new int[x];
— Creates new array of
x ints somwhere in memory; returns ponter to first array element created integer.
Assumes that x is compile-time constant. If it is a variable, this code is not valid. Your compiler might have extension to allow it. If it is the case, turn it off immediatly.
*new int[x];
— Dereferences returned pointer; returns value of first array element,
produces undefined behavior as variable is uninitialized.
pointer37[i] = *new int[x];
— Assigns said value to array element with index
i
This code leaks, as allocated memory never deleted and pointer to it is lost.
vxk wrote: |
---|
pointer371[i] = **new int*[x]; |
new int*[x];
— Creates new array of
x pointers to int somwhere in memory; returns ponter to first array element created integer.
Assumes that x is compile-time constant. If it is a variable, this code is not valid. Your compiler might have extension to allow it. If it is the case, turn it off immediatly.
*new int*[x];
— Dereferences returned pointer; returns value of first array element,
produces undefined behavior as variable is uninitialized.
**new int*[x];
— Dereferences value returned by previous operation. As we allocated array of pointers it would be a pointer to int, dereferenced it would be just value of stored int. This code
produces an undefined behavior and is likely to crash program as you are trying to dereference uninitialized pointer.
pointer371[i] = **new int*[x];
— Assigns said value to array element with index
i
This code leaks, as allocated memory never deleted and pointer to it is lost.
All that code is extremely bad and dangerous. It should not be written even for academic purposes.