Hi,
http://www.cprogramming.com/ans/ansmem.html
Question 2 is:
The correct (but incorrect) answer is b).#
Question #2
# Assuming that myObj is less than 1000 bytes, is there anything wrong with this code?
char x[1000];
myObj *obj = reinterpret_cast(x);
new (obj) myObj;]
a) Nope, it works fine
b) Yes, there could be byte alignment issues
c) Yes, the syntax for calling new is incorrect
1. I think the reinterpret_cast need the template type argument (at least msvc complains if it's not given), true?
2. ']' is a typo in line 4, true? If so, could someone correct it?
3. What header file needs to be included to call the placement new operator?
4. Why exactly could there be byte alignement issues? If "myObj is less than 1000 bytes", doesn't that mean "it is less than 1000 bytes, including any possible padding bytes (what's what the c++ sizeof operator understands by size)"?
Thank you!