Why does one work and other does not....

Discussion in 'C' started by An007kit, Oct 2, 2007.

  1. An007kit

    An007kit New Member

    Joined:
    Oct 1, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Am a student
    Location:
    Live in chandigarh, india
    These are the two codes...
    a)
    Code:
    #include<stdio.h>
    int i=5;
    void main()
    {
    int i=6;
    printf("%d",i);
    }
    output = 6
    b)
    Code:
    #include<stdio.h>
    void main()
    {
    extern int i;
    int i=6
    printf("%d",i);
    }
    int i=5;
    output=ERROR
     
    Last edited by a moderator: Oct 2, 2007
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Read up on scope. Learn to put your code in code tags.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice