Pages

Saturday, June 1, 2024

C Language Interview Question:What is the use of "##" operator in C

  #include <stdio.h>

#define concat(a, b) a##b

int main(void)

{

    int yx =7;

    printf("%d\n", concat(y, x));

    printf("%d\n", concat(3, 2));

    return 0;

}

OUTPUT

7

32


EXPLAINATION

the ## operator will concatinate the parameters passed to the macro

In the first case

                            concat(y, x) - the macro will output yx and pass its value to printf as yx is treated as a variable by printf

In the second case

                            concat(3, 2) - the macro will output 32 and printf will print 32 as its treated as an integer


No comments:

Post a Comment

What is anti- Debugging

  Anti- debugging is how we can stop somebody from debugging our system and getting all the information out of your subsystem.