Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. char *a;
  2.  
  3. void function()
  4. {
  5. if(a == NULL)
  6. {
  7. a = "Test1";
  8. }
  9. else
  10. {
  11. a = "Test2";
  12. }
  13. }
  14.  
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17.  
  18. char *a;
  19.  
  20. void function();
  21.  
  22. int main( int argc, const char *argv[] )
  23. {
  24. function();
  25. function();
  26. function();
  27. function();
  28.  
  29. return 0;
  30. }
  31.  
  32.  
  33. void function()
  34. {
  35. printf( "function: a=%s", (a ? a : "NULL") );
  36.  
  37. if(a == NULL)
  38. {
  39. a = "Test1";
  40. }
  41. else
  42. {
  43. a = "Test2";
  44. }
  45.  
  46. printf( " exiting a=%sn", (a ? a : "NULL") );
  47. }
  48.  
  49.  
  50. This produces the following output:
  51.  
  52. function: a=NULL exiting a=Test1
  53. function: a=Test1 exiting a=Test2
  54. function: a=Test2 exiting a=Test2
  55. function: a=Test2 exiting a=Test2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement