Guest User

Untitled

a guest
Aug 14th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. int n;
  2. int *variable = scanf("%d",&n);
  3. printf("Printing :%d",*variable);
  4.  
  5. int n;
  6. scanf("%d",&n);
  7. int *variable = &n;
  8. printf("Printing :%d",*variable);
  9.  
  10. int scanf(const char *format, ...);
  11.  
  12. int *variable = scanf("%d",&n);
  13.  
  14. *variable
  15.  
  16. int n;
  17. int *variable = &(scanf("%d",&n), n);
  18.  
  19. void foo(void)
  20. {
  21. int a;
  22. int *b = &a; //you assign the pointer `b` itself - no dereferencing
  23.  
  24. *b = 5; //you dereference the pointer and asssign the the referenced object
  25. }
  26.  
  27. void foo(void)
  28. {
  29. int a;
  30. int *b = &a; //b is pointing to the valid object -> the variable `a`
  31. int *c; //c is not pointing to valid object
  32. int *d; //d is not pointing to valid object
  33.  
  34. c = malloc(sizeof(*c)); //now c is pointing to the valid object (if malloc has not failed of course)
  35. *c = 5 // correct no UB
  36. *d = 5; // incorrect - UB
  37.  
  38.  
  39. *b = 5; //correct no UB
  40. }
Add Comment
Please, Sign In to add comment