Advertisement
RicardasSim

c pointer to struct as parameter

Dec 6th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. typedef struct{
  6.     float v1;
  7.     float v2;
  8. }testas;
  9.  
  10. testas tst;
  11.  
  12. int testF(testas *stst)
  13. {
  14.    
  15.     stst->v1+=1.0f;
  16.     stst->v2+=1.0f;
  17.    
  18.     return 0;
  19. }
  20.  
  21. int main (int argc, char **argv)
  22. {
  23.  
  24.     tst.v1=0.1f;
  25.     tst.v2=1.1f;
  26.  
  27.     printf("v1 before: %f\n",tst.v1);
  28.     printf("v2 before: %f\n",tst.v2);
  29.    
  30.     testF(&tst);
  31.    
  32.     printf("v1 after: %f\n",tst.v1);
  33.     printf("v2 after: %f\n",tst.v2);    
  34.  
  35. return 0;
  36. }
  37.  
  38. /*
  39. output:
  40.  
  41. v1 before: 0.100000
  42. v2 before: 1.100000
  43. v1 after: 1.100000
  44. v2 after: 2.100000
  45.  
  46. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement