The macro functions

Discussion in 'C' started by shubhadajs, Jan 24, 2011.

  1. shubhadajs

    shubhadajs New Member

    Joined:
    Jan 19, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Dear all
    I have a doubt regarding the macro function.


    #define SQR(x) (x*x)
    main()
    {
    int a,b=3;
    a= SQR(b+2);
    printf("%d",a);
    }

    The above program gives output as 11.
    And if I pass SQR(b+3), it gives o/p 15.

    How?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    3+2*3+2 is what you are getting when you expand the macro
     

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