#defines

N

Naren

Hello,

int main(){
int i=2,j=3;

printf("%d %d",i,j);

#define i j
#define j i

printf("%d %d",i,j);

}

What is the ouput in both the cases

Could anyone explain which tokens are considered while preprocessing.

Is the succesive preprocessor token replaced

thaanx in advance

Rgds,
Naren.
 
M

Martin Ambuhl

Naren said:
Hello,

int main(){
int i=2,j=3;

printf("%d %d",i,j);

#define i j
#define j i

printf("%d %d",i,j);

}

What is the ouput in both the cases

[modulo some whitespace]

int main()
{
int i = 2, j = 3;
printf("%d %d", i, j);
printf("%d %d", i, j);
}
 
B

Ben Pfaff

Naren said:
#define i j
#define j i

Could anyone explain which tokens are considered while preprocessing.

The preprocessor won't expand a macro name from within its own
expansion. So i expands to j, which expands to i, which ends the
chain of expansions. Similarly for j.

[snippage]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top