Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

structure initialization

The output of the code has to be zero, but I am having an error, please guide. I can initialize the structure with its type variable but how can I do with the pointer to initialize the whole structure?

#include<stdio.h>
typedef struct student
{
 int roll_id[10];
 int name_id[10];
 int postn;
} student;
int main()
{
 student p; /// here i can do student p={ {0} };
 student *pptr=&p;
 pptr= { {0} }; /// but can i initialize in this way ?? //error: expected 
 expression before ‘{’ token
 pptr->roll_id[9]=1;
 printf (" %d\n", pptr->postn); 
 return 0;
}

Answer*

Draft saved
Draft discarded
Cancel
1
  • I think it's valif IF he can do it with the variable. "student p; /// here i can do student p={ {0} };", just wanted to explain the mechanics. Commented Jan 8, 2013 at 11:05

lang-c

AltStyle によって変換されたページ (->オリジナル) /