Guys, ok after trying around stuff, I get that this is the way you initialize a structure in C.

#include<stdio.h>
#include<conio.h>

typedef struct s
{
  int data;
  char gender; 
}st;
st s1={5,'a'};

int main(void)
{
 printf("%d "%c",s1.data,s1.gender);

 getch();
 return 0;
}

But suppose i make a new instance of the structure, i again have to do a
st s2={5,'a'};

Couldnt this have been made much simpler if the structure could be defined as
typedef struct s

{
 int data = 5;
 char gender = 'a'
}s1,s2;

Couldnt this have been made much simpler if[...]

Yes, it could have. But like many features with the label "nice to have", the critical mass necessary to get it into the language specification wasn't ever reached. You might find a compiler that supports something along these lines as an extension though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.