GATE CSE
First time here? Checkout the FAQ!
x
0 votes
42 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 (11.1k points)   | 42 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

0 votes
1 answer
1
0 votes
2 answers
2
+1 vote
2 answers
3
asked in Programming by sh!va Veteran (20.7k points)   | 86 views
Top Users Feb 2017
  1. Arjun

    5490 Points

  2. Bikram

    4266 Points

  3. Habibkhan

    3972 Points

  4. Aboveallplayer

    3126 Points

  5. Debashish Deka

    2646 Points

  6. sriv_shubham

    2328 Points

  7. Smriti012

    2270 Points

  8. Arnabi

    2114 Points

  9. sh!va

    1780 Points

  10. mcjoshi

    1702 Points

Monthly Topper: Rs. 500 gift card

20,902 questions
26,048 answers
59,771 comments
22,184 users