695 views
1 votes
1 votes
#include <stdio.h>
#define crypt(s,t,u,m,p,e,d) m##s##u##t
#define begin crypt(a,n,i,m,a,t,e)
int begin()
{
    printf("Hello\n");
    return 0;
}

Options are :

(a) Hello (b) Link error (c) Segmentation fault (d) Compiler error

1 Answer

1 votes
1 votes

Answer A  Hello

Let us analyse the code:

  1. #include <stdio.h>
  2. #define crypt(s,t,u,m,p,e,d) m##s##u##t
  3. #define begin crypt(a,n,i,m,a,t,e)
  4. int begin()
  5. {
  6.     printf("Hello\n");
  7.     return 0;
  8. }

Line 1 : includes stdio.h 

Line 2: defined a macro crypt. It accepts 7 characters are makes a string with fourth, first, third and second letters and replaces the macro call with the result string. eg: crypt(b,d,c,a,e,f) replaces with abcd

Line 3: says that wherever string begin occurs, compiler should replace it with crypt(a,n,i,m,a,t,e) ie string main

Line 4: compiler sees begin here. Immediately it replaces begin with the string main (See point 3)

Now line 4 becomes int main()

Compiler detects a main programs. Thus function begin() is equivalent to main () program

hence "Hello" is printed.

edited by

Related questions

4 votes
4 votes
1 answer
1
ritwik_07 asked Jun 10, 2023
436 views
#include<stdio.h #include<string.h #define MAX(x, y) ((x) (y) ? (x) : (y)) int main() { int i = 10, j = 5, k = 0; k = MAX(i++, ++j); printf("%d %d %d", i, j, k); return ...
1 votes
1 votes
2 answers
2
Anushka Basu asked Jul 21, 2016
1,816 views
Please explain the solution.The output is 11 7 0#define MAX(x,y) (x) (y) ? (x) : (y) main() { int i = 10, j = 5, k = 0; k == MAX(i++, ++j); printf("%d %d %d", i,j,k); }W...
0 votes
0 votes
1 answer
3
Desert_Warrior asked May 16, 2016
2,356 views
#include<stdio.h int main() { int a = 5; int b = ++a * a++; printf("%d ",b); return 0; }(a) 25 (b) 30 (c) 36 (d) Undefined Behavior
0 votes
0 votes
2 answers
4
Desert_Warrior asked May 16, 2016
8,903 views
#include<stdio.h int main() { int a = 5; switch(a) { default: a = 4; case 6: a ; case 5: a = a+1; case 1: a = a-1; } printf("%d \n",a); return 0; }(a) 5 (b) 4 (c) 3 (d) N...