A Puzzle using C Program


Here we will see one C 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

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

Output

9648

Updated on: 20-Aug-2019

338 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements