C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - General Questions (Q.No. 1)
1.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
    int x=10, y=20;
    SWAP(x, y, int);
    printf("%d %d\n", x, y);
    return 0;
}
It compiles
Compiles with an warning
Not compile
Compiles and print nothing
Answer: Option
Explanation:
The code won't compile since declaration of t cannot occur within parenthesis.
Discussion:
25 comments Page 2 of 3.

Kamal said:   1 decade ago
(c t; t=a, a=b, b=t), this statement is wrong. c can't be used for int and in expression "t=a, a=b, b=t" the symbol (,) should be replaced with (;).

Wikiok said:   1 decade ago
After preprocessing:

int main()
{
int x=10, y=20;
(int t; t=x, x=y, y=t); //Error.
printf("%d %d\n", x, y);
return 0;
}

Anup singh said:   9 years ago
Hey, friends. Can anyone explain me the header file? Please.

#include

And why it is written in this bracket < >?
(1)

Sandeep said:   1 decade ago
#define SWAP(a, b, c){c t; t=a,a=b,b=t;} // this statement is wrong

SWAP(x, y, int); //here 3rd variable is not declare

Ganga said:   9 years ago
Why the swap is in header file. We can use the Capital letters when writing the c programme? Please tell me.
(1)

Surya said:   1 decade ago
main()
{
while(printf(""))
{
printf("gopi");
}
}

Please tell me execution process.
(1)

Trilok chand soni said:   1 decade ago
The code won't compile because here in this program declaration of the cannot occur within parenthesis.

Rahul Sharma said:   9 years ago
@Ganga.

You can use small letters.

When you are define the small letters in above programme.
(1)

Madhusudan said:   1 decade ago
In the function call, at the place of c they have used the keyword int....that's also an error.

Samira said:   1 decade ago
In (c t;t=a,a=b,b=t) before execution we can not get the value of c hence t is not declared


Post your comments here:

Your comments will be displayed after verification.