IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Declarations and Initializations - Discussion

@ : Home > C Programming > Declarations and Initializations > General Questions - Discussion

10. 

In the following program where is the variable a getting defined and where it is getting declared?

#include<stdio.h>
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

Answer: Option C

Explanation:

- During declaration we tell the datatype of the Variable.

- During definition the value is initialized.


Om Tripathi said: (Fri, Jun 25, 2010 01:35:04 PM)    
 
int a=20; is outside the main

Snehal Kadam said: (Thu, Jul 29, 2010 11:19:05 AM)    
 
In main, "extern int a" is declaration is ok.
but it is defined in outside;
so ,is the option c is correct???

Snehal Kadam said: (Thu, Jul 29, 2010 11:22:24 AM)    
 
In above option is D option correct??
in place of C

Vasudevan said: (Wed, Aug 25, 2010 03:26:44 AM)    
 
int a=20;(it is a outside of initialization)
how it consider for this program

Nandhi said: (Fri, Sep 24, 2010 06:23:15 AM)    
 
The variables are defined outside the main block, when that variable is declared as with the keyword 'extern'.

Murali Krishna said: (Fri, Oct 22, 2010 04:49:51 AM)    
 
What is the use of "extern" ?

Ravi Karthick said: (Fri, Dec 3, 2010 08:42:36 PM)    
 
Extern means external declaration that is declared for outside the function,so that a that is declared as extern and defined in outside the main ar a=20

Sindhu said: (Thu, Mar 3, 2011 09:46:49 AM)    
 
int a=20 is outside the main() so it is not considered as a declaration for a in given program

Prathyusha said: (Sat, Mar 5, 2011 03:12:44 AM)    
 
HI FRIENDS!

HERE IN THE PROGRAM PLEASE GO THROUGH THE QUESTION AGAIN.HE WAS JUST ASKING WHERE "a" IS DECLARED AND WHERE IT IS DEFINED.
WHETHER "a" IS NORMAL INTEGER OR EXTERNAL INTEGER NOT MATTERS.
SO,DECLARATION IS : extern int a;
AND DEFINITION IS :int a=20;
THAT'S IT!....

CORRECT ME IF I AM WRONG PLZ!.....

Kavita.C.Karjagar said: (Tue, Apr 26, 2011 03:08:17 AM)    
 
1.What is the difference between int a and extern int a?
2.when we use extern int a and int a?

Satyadev said: (Wed, Jun 1, 2011 12:15:27 PM)    
 
The definition of 'a' outside the function main is not valid, so it is not considered.

M.Dhilip Babu said: (Thu, Jul 7, 2011 09:28:20 AM)    
 
Why was declared int a=20 outside? suppose int a=20 declared inside of the function what is the o/p of this program?

Purnima said: (Fri, Sep 9, 2011 05:13:24 PM)    
 
Hi friends in my way if we declare extern int a;then we can use the variable a in any line or in may any function through out the programm, .

And if we declare int a;then it is local declaration here we can use a inside of the function only, if that function is closed then we can not use a in in another function.

Is it correct?

Aman said: (Sun, Oct 2, 2011 12:28:39 AM)    
 
When we have need to declare the extern variables? and what are its Benefits?

Bhavana said: (Wed, Oct 5, 2011 02:50:35 PM)    
 
I agree with prathyusha.

Mayank said: (Tue, Nov 29, 2011 12:22:36 AM)    
 
extern int a; indicates that the variable a is defined elsewhere, usually in a separate source code module.

printf("%d\n", a); it prints the value of local variable int a = 20. Because, whenever there is a conflict between local variable and global variable, local variable gets the highest priority. So it prints 20.

Rathika.B said: (Sun, Dec 25, 2011 10:51:21 AM)    
 
Please give an real example for "extern" keyword; Then only we know that how it works.

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!