RicardasSim

static

Jul 6th, 2019
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void ppr1()
  5. {
  6.     int a = 0;
  7.     static int b = 0;
  8.    
  9.     a++;
  10.     b++;
  11.    
  12.     printf("ppr1: a = %d, b = %d\n", a, b);
  13. }
  14.  
  15. void ppr2()
  16. {
  17.     int a = 0;
  18.     static int b = 0;
  19.    
  20.     a++;
  21.     b++;
  22.    
  23.     printf("ppr2: a = %d, b = %d\n", a, b);
  24. }
  25.  
  26. int main()
  27. {
  28.  
  29.     for(int i = 0; i<2; ++i) ppr1();
  30.    
  31.     printf("\n");
  32.    
  33.     for(int i = 0; i<3; ++i) ppr2();
  34.    
  35.     printf("\n");
  36.  
  37.     for(int i = 0; i<2; ++i) ppr1();
  38.    
  39.     printf("\n");
  40.  
  41.     for(int i = 0; i<3; ++i) ppr2();
  42.    
  43.     printf("\n");
  44.    
  45.     return 0;
  46. }
  47.  
  48. /*
  49. output:
  50.  
  51. ppr1: a = 1, b = 1
  52. ppr1: a = 1, b = 2
  53.  
  54. ppr2: a = 1, b = 1
  55. ppr2: a = 1, b = 2
  56. ppr2: a = 1, b = 3
  57.  
  58. ppr1: a = 1, b = 3
  59. ppr1: a = 1, b = 4
  60.  
  61. ppr2: a = 1, b = 4
  62. ppr2: a = 1, b = 5
  63. ppr2: a = 1, b = 6
  64.  
  65.  
  66. */
Advertisement
Add Comment
Please, Sign In to add comment