Cannot declare a struct in my function

Viewed 260

When I define a struct outside my main function there is there is no problem. But when I define it inside the main function it won't compile. Can anyone explain to me why or where is my mistake?

This works:

struct student 
{
    char first[100];
    char last[100];
    float grade3[3];
    float ave;
};

void print_out(struct student [] );
int main(int argc, char* argv[])
{
    struct student dd;
    // ...
    print_out(&dd);
    return 0;
}

void print_out(struct student st[])
{
    // ...
}

This does not:

void print_out(struct student [] );
int main(int argc, char* argv[])
{
    //the only change here by declaring structure inside main function
    struct student 
    {
      char first[100];
      char last[100];
      float grade3[3];
      float ave;
    };
    struct student dd;
    // ...
    print_out(&dd);
    return 0;
}

void print_out(struct student st[])
{
    // ...
}
2 Answers
Related