Re: Why this Code Works ??

Discussion in 'C Programming' started by John Tsiombikas (Nuclear / the Lab), Jun 30, 2003.

  1. James wrote:
    > int a ;
    > int a ;
    >
    > main ( ) {
    > a = 94 ;
    > printf ("%d\n", a) ;
    > }
    >
    > Why does this code compile without any warning.
    > If u initialise a. It is an error ?. Why ?.
    >
    >
    > regards,
    > jame


    It's perfectly legal, although kind of pointless to declare a twice...
    If you declare and initialize a twice then it would be an error
    (multiple definitions).
    Also if I may suggest, declare main explicitly as int main(void) and
    return 0; at the end.
    I would also advise you to use proper indentations for clarity, and
    don't forget to include <stdio.h> since you use printf

    -- Nuclear / the Lab --
     
    John Tsiombikas (Nuclear / the Lab), Jun 30, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F. GEIGER
    Replies:
    3
    Views:
    815
    F. GEIGER
    Aug 6, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    986
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,239
    Smokey Grindel
    Dec 2, 2006
  4. Alexander Burger

    getMethod() works and works not

    Alexander Burger, Nov 27, 2010, in forum: Java
    Replies:
    25
    Views:
    1,850
    Alexander Burger
    Nov 29, 2010
  5. abargaddon
    Replies:
    1
    Views:
    218
    clintmazur
    Feb 4, 2008
Loading...

Share This Page