C Programming - C Preprocessor - Discussion
|
|
|
|
Read more:"Forgiveness is a virtue of the brave."
- Indira Gandhi
|
| 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;
}
|
| [A]. |
It compiles | | [B]. |
Compiles with an warning | | [C]. |
Not compile | | [D]. |
Compiles and print nothing |
Answer: Option A
Explanation:
The code won't compile since declaration of t cannot occur within parenthesis.
|
|
Padhu said:
(Tue, Jul 27, 2010 12:16:02 PM)
|
|
| |
| Which parentheis that cannot occur |
|
Jeho said:
(Tue, Sep 14, 2010 10:20:19 AM)
|
|
| |
What ever we defined after # symbol is called preprocessor.
Here they used preprocessor function. Every function has to be declared before defined.
(a, b, c) is declaration in which t is not declared.
(c, t;t=a;a=b) is function t is used. |
|
Wikiok said:
(Sat, Apr 9, 2011 03:46:47 PM)
|
|
| |
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;
} |
|
Madhusudan said:
(Thu, Jul 21, 2011 02:39:44 PM)
|
|
| |
| In the function call, at the place of c they have used the keyword int....that's also an error. |
|
Kamal said:
(Sat, Oct 1, 2011 09:10:33 PM)
|
|
| |
| (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 (;). |
|
Trilok Chand Soni said:
(Sun, Nov 27, 2011 06:45:56 AM)
|
|
| |
| The code won't compile because here in this program declaration of the cannot occur within parenthesis. |
|
Samira said:
(Mon, Jan 23, 2012 03:43:07 PM)
|
|
| |
| In (c t;t=a,a=b,b=t) before execution we can not get the value of c hence t is not declared |
|
|