extern keyword

This is a discussion on extern keyword within the C++ Programming forums, part of the General Programming Boards category; what is the extern keyword for....

  1. #1
    Shadow12345
    Guest

    extern keyword

    what is the extern keyword for.

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    317
    extern allows you to use global variables defined in one file( remember they have file scope) in another file. For example:
    Code:
    //file 1
    int Cats = 5
    void printcats(){
            cout<<Cats;
    }
    
    //file 2
    
    extern int Cats //declare variable in current file
    void ShowCats(){
            cout<<Cats;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. extern classes
    By Swordsman in forum C++ Programming
    Replies: 1
    Last Post: 05-07-2008, 03:07 AM
  2. usage of extern keyword
    By ilikepure in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2007, 07:24 PM
  3. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  4. extern keyword
    By trekker in forum C Programming
    Replies: 7
    Last Post: 06-01-2005, 02:31 PM
  5. extern keyword and structures
    By GuitGentlyWeeps in forum C Programming
    Replies: 2
    Last Post: 01-30-2002, 07:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21