RicardasSim

struct fnc parameter

Feb 28th, 2024
1,855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct{
  5.      int a;
  6.      int b;
  7. } St;
  8.  
  9. void Fnc1( St s )
  10. {
  11.     s.a += 1;
  12.     s.b += 2;
  13.  
  14.     printf("(f1) %d %d \n", s.a, s.b );
  15. }
  16.  
  17. void Fnc2( St *p_s )
  18. {
  19.     p_s->a += 1;
  20.     p_s->b += 2;
  21.  
  22.     printf("(f2) %d %d \n", p_s->a, p_s->b );
  23. }
  24.  
  25. int main()
  26. {
  27.  
  28.     St s_1;
  29.  
  30.     s_1.a = 1;
  31.     s_1.b = 2;
  32.  
  33.     printf("(1) %d %d \n", s_1.a, s_1.b );
  34.  
  35.     Fnc1( s_1 );
  36.  
  37.     printf("(2) %d %d \n", s_1.a, s_1.b );
  38.  
  39.     Fnc2( &s_1 );
  40.  
  41.     printf("(3) %d %d \n", s_1.a, s_1.b );
  42.  
  43.     return 0;
  44. }
  45.  
  46. /*
  47.  
  48. output:
  49.  
  50. (1) 1 2
  51. (f1) 2 4
  52. (2) 1 2
  53. (f2) 2 4
  54. (3) 2 4
  55.  
  56. */
  57.  
Advertisement