fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. struct test_s
  6. {
  7. float val ;
  8. int bol ;
  9.  
  10. } ;
  11.  
  12. #define LEN 5
  13.  
  14. struct test_s mystr[LEN] ;
  15.  
  16. int main( void )
  17. {
  18. for( int i = 0 ; i < LEN ; i += 1 )
  19. {
  20. mystr[i].val = 321.0f ;
  21. mystr[i].bol = 1 ;
  22. }
  23.  
  24. for( int i = 0 ; i < LEN ; i += 1 )
  25. printf( "\n %f %d" , mystr[i].val , mystr[i].bol ) ;
  26.  
  27. for( int i = 0 ; i < LEN ; i += 1 )
  28. mystr[i].val = 0.0f ; //set only val to 0
  29.  
  30. for( int i = 0 ; i < LEN ; i += 1 )
  31. printf( "\n %f %d" , mystr[i].val , mystr[i].bol ) ; //both values get printed as 0, WRONG!
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
 321.000000   1
 321.000000   1
 321.000000   1
 321.000000   1
 321.000000   1
 0.000000   1
 0.000000   1
 0.000000   1
 0.000000   1
 0.000000   1