A C Programming Language Puzzle?

CServer Side ProgrammingProgramming

Here we will see one C programming language puzzle question. Suppose we have two numbers 48 and 96. We have to add the first number after the second one. So final result will be like 9648. But we cannot use any logical, arithmetic, string related operations, also cannot use any pre-defined functions. So how can we do that?

This is easy. We can do by using Token Pasting operator(##) in C. The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the macro definition.

Example

 Live Demo

#include<stdio.h>
#define MERGE(x, y) y##x
main() {
   printf("%d", MERGE(48, 96));
}

Output

9648
raja
Published on 24-Jul-2019 15:39:44
Advertisements