GATE CSE
First time here? Checkout the FAQ!
x
0 votes
50 views
In the following program where is the variable a getting defined and where it is getting declared?

#include

int main()

{ extern int a;

printf("%d\n", a);

return 0;

} int a=20;

(a) extern int a is declaration, int a = 20 is the definition

(b) int a = 20 is declaration, extern int a is the definition

(c) int a = 20 is definition, a is not defined

(d) a is declared, a is not defined
asked in Programming by Veteran (13k points)   | 50 views
Answer is A .

Extern int a declares that there will be a variable a of integer type in upcoming lines.

Int a=20 defines the variable
is 'a' used in both places same??as it is outside main()

http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/

Please refer to this link to know more about extern variables!!

Please log in or register to answer this question.

Related questions



Top Users May 2017
  1. akash.dinkar12

    3154 Points

  2. pawan kumarln

    1630 Points

  3. sh!va

    1590 Points

  4. Arjun

    1350 Points

  5. Devshree Dubey

    1246 Points

  6. Angkit

    1044 Points

  7. Debashish Deka

    1022 Points

  8. Bikram

    972 Points

  9. LeenSharma

    820 Points

  10. Prashant.

    692 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. pawan kumarln

    256 Points

  2. Ahwan

    232 Points

  3. jjayantamahata

    114 Points

  4. joshi_nitish

    114 Points

  5. Arnab Bhadra

    94 Points


22,731 questions
29,061 answers
65,094 comments
27,625 users