#defines

Discussion in 'C Programming' started by Naren, Aug 27, 2003.

  1. Naren

    Naren Guest

    Hello,

    int main(){
    int i=2,j=3;

    printf("%d %d",i,j);

    #define i j
    #define j i

    printf("%d %d",i,j);

    }

    What is the ouput in both the cases

    Could anyone explain which tokens are considered while preprocessing.

    Is the succesive preprocessor token replaced

    thaanx in advance

    Rgds,
    Naren.
    Naren, Aug 27, 2003
    #1
    1. Advertising

  2. Naren wrote:

    > Hello,
    >
    > int main(){
    > int i=2,j=3;
    >
    > printf("%d %d",i,j);
    >
    > #define i j
    > #define j i
    >
    > printf("%d %d",i,j);
    >
    > }
    >
    > What is the ouput in both the cases


    [modulo some whitespace]

    int main()
    {
    int i = 2, j = 3;
    printf("%d %d", i, j);
    printf("%d %d", i, j);
    }





    --
    Martin Ambuhl
    Martin Ambuhl, Aug 27, 2003
    #2
    1. Advertising

  3. Naren

    Ben Pfaff Guest

    "Naren" <> writes:

    > #define i j
    > #define j i
    >
    > Could anyone explain which tokens are considered while preprocessing.


    The preprocessor won't expand a macro name from within its own
    expansion. So i expands to j, which expands to i, which ends the
    chain of expansions. Similarly for j.

    [snippage]
    --
    "Some programming practices beg for errors;
    this one is like calling an 800 number
    and having errors delivered to your door."
    --Steve McConnell
    Ben Pfaff, Aug 27, 2003
    #3
    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. Replies:
    5
    Views:
    3,391
    Brian Drummond
    Feb 24, 2006
  2. Rob R. Ainscough
    Replies:
    1
    Views:
    408
    =?Utf-8?B?RGVhc3Vu?=
    Jun 27, 2005
  3. John Leonard
    Replies:
    2
    Views:
    377
    Rick Genter
    Sep 28, 2003
  4. exquisitus
    Replies:
    12
    Views:
    22,405
    Tilman Bohn
    Feb 19, 2005
  5. theotyflos
    Replies:
    3
    Views:
    468
    Thomas Matthews
    Feb 19, 2004
Loading...

Share This Page