Amit Singh Tomar
Amit Singh Tomar

Reputation: 8610

What this Declaration meant in C

I have a structure in C and at end have some declration which not able to decode

struct Student
{
   int roll;
   char name;
   int age;
};

extern struct Student dev[];

what does last statement mean in C??

Upvotes: 0

Views: 90

Answers (3)

loganaayahee
loganaayahee

Reputation: 819

        struct students
    {
    int num;
    char name[100];
    char dept[100];
   } extern struct students student[];

student[] is the structure array.its used for the access the structure members like num,name,dept.

int j=100;

             #include<stdio.h>

                   main(){

                  for(i=0;i<j;i++)
                         {
                               scanf("%d",&student[i].num);
                               scanf("%s",student[i].name);
                               scanf("%s",student[i].dept);
                           }


                        for(i=0;i<j;i++)
                            {
                                  printf("%d\n",student[i].num);
                                  printf("%s\n",student[i].name);
                                   printf("%s\n",student[i].dept);
     }
     }

It is used to the access the 100 records of members of the structure

Upvotes: 0

Alok Save
Alok Save

Reputation: 206508

extern struct Student dev[];

Tells the compiler that dev is an array of the type struct Student and it is defined somewhere else(other translation unit).

Upvotes: 4

Bart Friederichs
Bart Friederichs

Reputation: 33491

It means that dev[] is not declared in this C/object file, but in another. You'll have to link that other object to your binary to be able to use that variable.

Upvotes: 2

Related Questions