I know that #define replaced before the compiling to real values. so why the first code here compile with no error, and the 2nd not?
the 1st;
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("bc");
return 0;
}
the 2nd(not working);
#include <stdio.h>
#include <stdlib.h>
#define Str "bc";
int main()
{
printf(Str);
return 0;
}
error: expected ')' before ';' token
thank you for the answers, and sorry about my poor English…
Because the
Strmacro evaluates to"bc";— the semicolon is included. So your macro expands to:You do not need to follow a #define with a semicolon. They end at a newline, rather than at the semicolon like a C statement. It is confusing, I know; the C preprocessor is a strange beast and was invented before people knew better.