M
mdh
As I begin to write more little programs without the help of the
exercises, little things pop up that I need to understand more fully.
Thus, below, and although this is not the exact code, the principle of
the question is the same, ( I hope )
#include <stdio.h>
int i = 0;
int main () { return 0; } /* no errors or warnings*/
but
#include <stdio.h>
int i ;
i=0;
int main () { return 0; } /* 2 warnings. */
I think one of the regular contributors has previously alluded to this
issue, but I wish to understand the principle more clearly.
So, ???
1) int i = 0 is allowed because i is declared and initialized as an
ext variable.
2) int i; i = 0 is not allowed because ?
a) even though my intention is to assign '0' to i , this can only
occur within a function?
b) the compiler thinks I am once again declaring 'i', which has
previously been declared, even though my **intent** is to initialize
an external variable.
I assume the same principles would apply if declared i as "static".
What key principle am I missing.
Thank you as usual.
exercises, little things pop up that I need to understand more fully.
Thus, below, and although this is not the exact code, the principle of
the question is the same, ( I hope )
#include <stdio.h>
int i = 0;
int main () { return 0; } /* no errors or warnings*/
but
#include <stdio.h>
int i ;
i=0;
int main () { return 0; } /* 2 warnings. */
I think one of the regular contributors has previously alluded to this
issue, but I wish to understand the principle more clearly.
So, ???
1) int i = 0 is allowed because i is declared and initialized as an
ext variable.
2) int i; i = 0 is not allowed because ?
a) even though my intention is to assign '0' to i , this can only
occur within a function?
b) the compiler thinks I am once again declaring 'i', which has
previously been declared, even though my **intent** is to initialize
an external variable.
I assume the same principles would apply if declared i as "static".
What key principle am I missing.
Thank you as usual.