fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main ()
  5. {
  6. // myStruct is a struct type that has 2 fields
  7. typedef struct{
  8. int AnInt;
  9. float AFloat;
  10. } myStruct;
  11. // make an instance of myStruct called M using the typedef
  12. myStruct M[3] = {{1, 1.5f}, {2, 2.5f}, {3, 3.5f}};
  13. int index;
  14. for (index = 0; index < 3; index++)
  15. printf ("M[%d] has values:\n AnInt=%d\n AFloat=%f\n",
  16. index, M[index].AnInt, M[index].AFloat);
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
M[0] has values:
 AnInt=1
 AFloat=1.500000
M[1] has values:
 AnInt=2
 AFloat=2.500000
M[2] has values:
 AnInt=3
 AFloat=3.500000