The output of the code below is
int *m();
void main()
{
int k = m();
printf("%d", k);
}
int *m()
{
int a[2] = {5, 8};
return a;
}
Answer: D
Correct answer: Varies
Two faults compound each other. The function returns a pointer to a local array that no longer exists, and the caller assigns that pointer to an int. What is printed is an address reinterpreted as an integer - different on every run and every machine.
Please log in or register to report this question.