RicardasSim

initialize a struct C

Aug 1st, 2019
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. //-std=c99 -Wall -Wextra -Wpedantic -Wshadow
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. typedef struct Item {
  7.     int a;
  8.     int b;
  9. } Item;
  10.  
  11.  
  12. int main()
  13. {
  14.     Item item = { 1, 2 };
  15.  
  16.     Item item1;
  17.    
  18.     item1 = (Item){ 1, 2 };
  19.  
  20.     Item item2;
  21.    
  22.     item2 = (Item){ .a=1, .b=2 };
  23.    
  24.     printf("%d %d\n%d %d\n%d %d\n",item.a,item.b,item1.a,item1.b,item2.a,item2.b);
  25.        
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment