Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In addition to the other answers posted, in question 5 you have <em>undefined behavior</em>.</p> <p><em>{Language lawyers, please confirm the this issue}</em><br> In the constructor, the characters are copied from the string one by one into a character array; <em>without a terminating nul character</em>. The <code>print</code> method treats the array of characters as a C-style string and the <code>cout</code> operation will print all the characters in <code>data</code> (and beyond), until it finds a terminating nul character. The <code>std::basic_string</code> data structure may not store a terminating nul character as part of the string.</p> <p>There is no copy constructor for the class, so the compiler creates a copy constructor that copies the pointer. Thus there will be two instances pointing to the same data. </p> <p>In the inner block, the outer instance is assigned to the instance created in the inner block. The inner instance is temporary and the pointer in the outer variable points to the data of a temporary object. </p> <p>After the statement block disappears, the pointer in the outer variable is now pointing to a location that isn't used and the expected data isn't there anymore (the expected data was removed when the execution left the scope of the inner statement block). Thus the <code>data</code> pointer of the <code>outer</code> variable is pointing to unknown data or unknown location (the OS may have paged out the data). This is undefined behavior.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload