description about error in following prog

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vivek verma
    New Member
    • Feb 2010
    • 6

    description about error in following prog

    [code]
    main()
    {
    extern int i;
    i=20;
    print("%d",size of(i));
    }
    [\code]
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Please tell us why you think there is an error in this program. Did you get a build error? Was there something wrong with the output?

    Comment

    • vivek verma
      New Member
      • Feb 2010
      • 6

      #3
      error at compile time and error is
      LINKER ERROR :undefined symbol i

      Comment

      • Joseph Martell
        Recognized Expert New Member
        • Jan 2010
        • 198

        #4
        You declared i as
        Code:
        extern int i;
        Notice that this is a declaration, not a definition. You basically told the linker that you are relying on i being defined in another place, but the linker couldn't find any definition for i.

        Is there a reason that you need the extern keyword? Dropping it should allow this to compile just fine.

        Oh, and a technical point: this is actually a link error, not a compilation error. Its worth reading a little bit about the differences. It can help with your troubleshooting .

        Comment

        • vivek verma
          New Member
          • Feb 2010
          • 6

          #5
          thanks
          I got my ans

          Comment

          Working...