Need Training Material.....

This is a discussion on Need Training Material..... within the C Programming forums, part of the General Programming Boards category; Hi, Could any explain the below code. Code: #include<stdio.h> #include<string.h> #define f(a,b) a##b int main() { printf("%d\n",f(1,2)); } The output ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Bangalore, INDIA
    Posts
    43

    Need Training Material.....

    Hi,
    Could any explain the below code.

    Code:
    #include<stdio.h>
    #include<string.h>
    
    #define f(a,b) a##b
    
    int main()
    {
           printf("%d\n",f(1,2));
    }
    The output of the above code is 12, but if I try as below it gives error why is it so, and if any know about the tutorial on such things please let me know

    Code:
    #include<stdio.h>
    int main()
    {
            printf("%d\n", 1##2);
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    ## is only meaningful in macros.


    The C preprocessor is not part of the C compiler. The C compiler itself understands very few uses of #.

    http://vergil.chemistry.gatech.edu/r...al/basic2.html
    Skim down to "The C Preprocessor :: Overview"



    Quote Originally Posted by enggabhinandan
    Hi,
    Could any explain the below code.

    Code:
    #include<stdio.h>
    #include<string.h>
    
    #define f(a,b) a##b
    
    int main()
    {
           printf("%d\n",f(1,2));
    }
    The output of the above code is 12, but if I try as below it gives error why is it so, and if any know about the tutorial on such things please let me know

    Code:
    #include<stdio.h>
    int main()
    {
            printf("%d\n", 1##2);
    }
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    Bangalore, INDIA
    Posts
    43
    Hey below is the link which i found bit useful to understand MACROS...


    http://gcc.gnu.org/onlinedocs/cpp/Macros.html#Macros

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Perhaps you would benefit from a more organised approach to learning C (say a book), or maybe
    http://www.eskimo.com/~scs/cclass/notes/top.html

    Searching the web for random stuff then posting the results here isn't going to teach you much at all in the long run.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C] GDI: how to erase material drawn at an entire screen DC
    By pc2-brazil in forum Windows Programming
    Replies: 3
    Last Post: 01-24-2009, 06:24 PM
  2. More material like this?
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-13-2007, 07:57 PM
  3. api reference material
    By eth0 in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2006, 05:26 PM
  4. Training
    By gvector1 in forum Windows Programming
    Replies: 13
    Last Post: 03-10-2003, 11:55 AM
  5. c++ Training
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 06-07-2002, 01:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21