fork download
  1. #include <stdio.h>
  2.  
  3. void CauseUB(int a, int **b) {
  4. *b = &a;
  5. }
  6. int main() {
  7. int x = 5, *y = &x;
  8. printf("This is OK: %d\n", *y);
  9. CauseUB(x, &y); // Pointer to pointer
  10. printf("Make sure stuff gets placed on the stack... %d\n", 2*x+13);
  11. printf("This is UB: %d\n", *y);
  12. return 0;
  13. }
  14.  
  15.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
This is OK: 5
Make sure stuff gets placed on the stack... 23
This is UB: 134514112