IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET

C Programming - C Preprocessor - Discussion

@ : Home > C Programming > C Preprocessor > General Questions - Discussion

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

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!