I take an online test in C (not for work, only for myself), and I constantly encounter questions of this type using a hash symbol. I assume this is not a typo and I am not familiar with this use of the hash symbol.
#include <stdio.h>
int* func()
{
int num = 10;
return #
}
int main()
{
int *ptr = func();
printf("%d\n", *ptr);
return 0;
}
What is the output of the above C code?
The answer is that this is a runtime error and explanation
The variable defined in the function will be allocated in the stack segment, which will be deleted when the function returns. Therefore, access to the address of these variables leads to a segmentation error.
source
share