C Preprocessor

Q1:
What will be the output of the program?
#include<stdio.h>
#define SWAP(a, b) int t; t=a, a=b, b=t;
int main()
{
    int a=10, b=12;
    SWAP(a, b);
    printf("a = %d, b = %d\n", a, b);
    return 0;
}

A Error: Undefined symbol 't'

B a = 12, b = 10

C Error: Declaration not allowed in macro

D a = 10, b = 12

ANS:B - a = 12, b = 10

The macro SWAP(a, b) int t; t=a, a=b, b=t; swaps the value of the given two variable. Step 1: int a=10, b=12; The variable a and b are declared as an integer type and initialized to 10, 12 respectively. Step 2: SWAP(a, b);. Here the macro is substituted and it swaps the value to variable a and b. Hence the output of the program is 12, 10.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.