Thread: diff b/w static & external variables

  1. #1
    Registered User
    Join Date
    Apr 2006

    diff b/w static & external variables

    hey cud i know the difference between static & external variables??

  2. #2
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    When you define a variable as extern you are just telling the compiler that the variable is defined in another object and that it won't find the variable's definition in this file. If you didn't do this the compiler would not know where the variable resides in your executable, and if you try to redefine it you will get linker errors because the same thing is created in two different spots.
    A static variable can be thought of as a global variable with local scope.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Yes and no. You can have static variables defined in functions also. For that matter, you can even have static functions. This is stuff covered in any basic C book.

    Hope is the first step on the road to disappointment.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    ...and about a *billion websites that can be found with google.

    *: This is an understatement
    Sent from my iPad®

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. defining macros or static variables
    By l2u in forum C++ Programming
    Replies: 15
    Last Post: 08-05-2008, 06:28 AM
  2. static variables
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 08-28-2006, 06:35 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Replies: 2
    Last Post: 12-25-2001, 04:18 PM