see once in hurry i have written
#include <stdio.h>
static flag;
int main()
{
printf("flag is %d",flag);
return 0;
}
it does not not give any warning or error and works fine. I dont understand why this is going work?
see once in hurry i have written
#include <stdio.h>
static flag;
int main()
{
printf("flag is %d",flag);
return 0;
}
it does not not give any warning or error and works fine. I dont understand why this is going work?
C assumes int
when type is missing. It is also true for function definitions and their parameters:
// same as int add(int x, int y)
add(x,y) { return x + y; }
// same as int main()
main()
{
}
When int
is used in conjunction with another keyword, int
is optional
static int <--> static
volatile int <--> volatile
short int <--> short
long int <--> long
While short
and long
are accepted short forms, you should avoid leaving it out in conjunction with storage keywords (static
, volatile
).
Primary datatypes are
char , int , float , double
the Storage classes like
auto,static,extern etc
data type modifiers like
long,signed,unsigned etc,
if the storage classes or datatype modifiers miss the primary datatype of the variable then the compiler treats them as integer by default and even if function return types are not defined they are treated as int by default
example
long i is similar to long int i
static i is similar to static int i
But you cant simply say i and ask why compiler doesnt treat it as int
flag is initialized to 0, as a global static variable. other languages like Java will give an error if you try to use an uninitialized variable. i'm assuming this is C, in which case flag defaults to type int. please don't ever do this. it's really bad programming practice.