Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can anybody tell me the way of getting this answer

Can anybody tell me the way of getting this answer

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    philiptabraham
    wrote on last edited by
    #1

    Can anybody tell me the way os getting this answer #define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12))); } Ans:100 Thanks in advance

    D D 2 Replies Last reply
    0
    • P philiptabraham

      Can anybody tell me the way os getting this answer #define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12))); } Ans:100 Thanks in advance

      D Offline
      D Offline
      Don Box
      wrote on last edited by
      #2

      Upon Preprocessing completion (but before compilation), the statement printf("%d",f(var,12))); gets expanded to printf("%d",var12)). So the answer, 100. In macro f(g, g2), u r passing var and 12. The statement g##g2 joins the original parameter to the macro i.e, var##12 = var12. Hence the resulting variable, var12

      Come online at:- jubinc@skype

      1 Reply Last reply
      0
      • P philiptabraham

        Can anybody tell me the way os getting this answer #define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12))); } Ans:100 Thanks in advance

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Have you considered compiling with the /P switch to see just what the preprocessor resolves the macro to?

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups