I am pretty new to C++ and recently did a test. Today I got the test results back however some of the test answers didn't match up to the result of the question. For instance one of the questions was:
What, if anything, is wrong with the following program?
#include <iostream.h>
int * EncryptNumber(int w)
{
int *z_ptr = &w;
w++;
return z_ptr;
}
void main()
{
int a;
cin >> a;
cout << *(EncryptNumber(a));
}
A ) The pointer 'z_ptr' is returned and the value of the variable it points to is displayed on the screen.
B ) The pointer 'z_ptr' is returned and its memory address is displayed on the screen.
C ) The pointer 'z_ptr' is not declared in an appropriate manner, causing the program to crash.
D ) The pointer 'z_ptr' is returned but the variable it points to goes out of scope, causing the program to crash.
I answered the question with A and it was marked as a wrong answer, however I tested the code by compiling it and it worked.
Does anyone else think the answer should have been anything other than A? If so why? Or do you agree A should be the correct answer?

New Topic/Question
Reply


MultiQuote




|