tags:

views:

37

answers:

5
#include<conio.h>
#include<stdio.h>
#define abc 7

int main()
{

int abc=1;

printf("%d",abc);

getch();

return 0;
}

why this program is giving compile time error

+3  A: 

You're assigning 7=1 which is invalid. Since you've defined abc to be 7, the preprocessor translates the line:

int abc=1;

to:

int 7=1;

Which is a syntax error in C (my gcc says syntax error before numeric constant).

Eli Bendersky
A: 

The C preprocessor does a blind replacement of abc with 7 resulting in:

int 7=1;

which clearly is an error.

codaddict
A: 

When the preprocessor replaces abc with 7, the following line becomes invalid:

int 7=1;

An identifier in C, can't be just a number.

AraK
+2  A: 

You define abc as 7.

Then int abc=1 is transformed into int 7=1 which is absurd.

Why are you doing this?

Daniel Daranas
+2  A: 

You declare "abc" macro value as 7 . So if again include the macro name as variable, it will give error.

consider the following

abc value is 7. So it will treated as 7=1. So that it will give error.

muruga