CrazyEngineers
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • gaurav.bhorkar

    MemberSep 23, 2011

    When you write extern int a; - it is a declaration not a definition. The extern keyword says that the variable is defined outside the function block.

    The following code will explain this:
    void func( );
    
    void main ( )
    {
        func ( );
    }
    
    void func ( )
    {
        extern int var; //declaring a variable var which is outside the scope of this function (i.e. our global variable)
        printf ("%d", var);
    }
    
    int var = 10; //Defining a global variable. This can be in another file also
    Note that we have declared (and defined) our global variable 'var' outside the func( ) block, and also way below the func ( ).
    Had we defined the global variable 'var' above the func() block, we wouldn't have to declare it using the extern keyword.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register