开发者

symbolic constants

开发者 https://www.devze.com 2022-12-23 07:24 出处:网络
#include<conio.h> #include<stdio.h> #define abc 7 int main() { int abc=1; printf(\"%d\",abc); getch();
#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 com开发者_运维百科pile time error


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).


You define abc as 7.

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

Why are you doing this?


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.


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

int 7=1;

which clearly is an error.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消