The Wayback Machine - https://web.archive.org/web/20211021065427/https://www.geeksforgeeks.org/a-c-puzzle/
Skip to content
Related Articles

Related Articles

Improve Article

A C Programming Language Puzzle

  • Difficulty Level : Easy
  • Last Updated : 21 Jun, 2018
Geek Week

Give a = 12 and b = 36 write a C function/macro that returns 3612 without using arithmetic, strings and predefined functions.

We strongly recommend you to minimize your browser and try this yourself first.

Below is one solution that uses String Token-Pasting Operator (##) of C macros. For example, the expression “a##b” prints concatenation of ‘a’ and ‘b’.

Below is a working C code.




#include <stdio.h>
#define merge(a, b) b##a
int main(void)
{
    printf("%d ", merge(12, 36));
    return 0;
}

Output:

3612

Thanks to an anonymous user to suggest this solution.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Take a step-up from those “Hello World” programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.
My Personal Notes arrow_drop_up
Recommended Articles
Page :