GATE CSE
First time here? Checkout the FAQ!
x
0 votes
44 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 (12.6k points)   | 44 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 (24.2k points)   | 94 views


Top Users Mar 2017
  1. rude

    5236 Points

  2. sh!va

    3054 Points

  3. Rahul Jain25

    2920 Points

  4. Kapil

    2732 Points

  5. Debashish Deka

    2602 Points

  6. 2018

    1574 Points

  7. Vignesh Sekar

    1422 Points

  8. Akriti sood

    1402 Points

  9. Bikram

    1384 Points

  10. Sanjay Sharma

    1128 Points

Monthly Topper: Rs. 500 gift card

21,545 questions
26,881 answers
61,232 comments
23,243 users