Within the same function, is it UB to access—through indirection—a local variable not in scope?
问题 After the second closing brace, b is accessible only through indirection through a . int main() { int *a; { int b = 42; a = &b; } printf("%d", *a); // UB? return 0; } Since b is not anymore in scope, is this UB? I know it's UB to dereference a pointer to a non-static local variable from a function that has already returned, but in this case everything is within the same function. This is UB in C++, but I'm not sure about C. 回答1: Yes, it's undefined behaviour to access any variable that has