vaibhav shukla
vaibhav shukla

Reputation: 1

using extern with different type but same name variable in C

I have int a[] in one C file. Now in another .c file I have extern int *a .

I need to know what will be the behavior if I try to access variable a in second file and why? What all problems would occur?

Upvotes: 0

Views: 308

Answers (2)

Dineshkumar
Dineshkumar

Reputation: 4245

If you include the file(declaration) twice or declared variable named a, then there may be error redefinition of a;

when i tried the above compiler shows error :

conflicting types for a;
//previous definition in other file...

Upvotes: 0

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272537

Undefined behaviour. So anything might happen.

Upvotes: 2

Related Questions