RicardasSim icon

initialize a struct C

RicardasSim | PRO | 08/01/19 09:04:14 PM UTC | 0 ⭐ | 597 👁️ | Never ⏰ | []
C |

420 B

|

None

|

0 👍

/

0 👎

//-std=c99 -Wall -Wextra -Wpedantic -Wshadow
 
#include <stdio.h>
#include <stdlib.h>
 
typedef struct Item {
    int a;
    int b;
} Item;
 
 
int main()
{
    Item item = { 1, 2 };
 
    Item item1;
    
    item1 = (Item){ 1, 2 };
 
    Item item2;
    
    item2 = (Item){ .a=1, .b=2 };
    
    printf("%d %d\n%d %d\n%d %d\n",item.a,item.b,item1.a,item1.b,item2.a,item2.b);
        
    return 0;
}

Comments