# regarding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeyshree
    New Member
    • Jul 2010
    • 75

    # regarding

    Hai,
    I have a doubt.Please do look at the snippet below and answer my question.
    Code:
    #include<stdio.h>
    #include<conio.h>
    #define f(g,g2) g##g2
    main()
    {
    int var12=100;
    clrscr();
    printf("%d",f(var,12));
    getch();
    }
    The output of this program is 100.
    What is the function of # here?Please do clear my doubt.Thanks in advance
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    the # (pound sign) by itself performs no action and is a null pre-processing directive.
    the #include (pound sign ahead of "include")i s a pre-processing directive to include the file named in angle brackets(<>)in the translation unit thus replacing the directive with the file.
    the ## operator(double pound sign)concatenat es arguments. The pre-processor takes the arguments that match the parameter references on either side of the ## operator and converts them to a single token.e.g.
    Code:
    #include<iostream>
    #define Amalgamate(a,b,c) a ## b ## c
    
    int main()
    {  
       unsigned amalgam = Amalgamate(5,12,17);
       std::cout<<amalgam;//prints 51217 to screen
       return 0;
    }
    I've just finished reading about this in Al Stevens book "Teach Yourself C++"!

    Comment

    Working...