Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Language in C Interview Questions and Answers

Ques. If we have declared an array as global in one file and we are using it in another file then why doesn't the sizeof operator works on an extern array?

Ans. An extern array is of incomplete type as it does not contain the size. Hence we cannot use sizeof operator, as it cannot get the size of the array declared in another file. To resolve this use any of one the following two solutions:
1. In the same file declare one more variable that holds the size of array. For example,


int arr[5] ;
int arrsz = sizeof ( arr ) ;


extern int arr[] ;
extern int arrsz ;
2. Define a macro which can be used in an array
declaration. For example,


#define SZ 5


#include "myheader.h"
int arr[SZ] ;


#include "myheader.h"
extern int arr[SZ] ;

Is it helpful? Yes No

Most helpful rated by users:

©2020 WithoutBook