This piece of code seems to be creating some troubles while compiling. Any explanation?
int i =20;
int maxlen = i;
int main()
{
int j = i;
printf("i=%d , j=%d\n", i , j);
}
In C, you can't initialize global variables using non-constant expressions. Initializing maxlen to i fails because i
is not a constant expression. It's part of the C standard.
Why not #define
a constant?
#define MAXLEN 20
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With