The default value of an uninitialized static int is zero. What about if the datatype is a char?
#include<stdio.h>
int main()
{
static char i;
printf("%c", i);
return 0;
}
This program executes without giving any output - why?
CodePudding user response:
In your example, i is default initialized to zero, and when you output that as a character using printf with the %c format you are outputting the null character \0, which is why you don't see anything.
If you wanted to see the numerical value, you should use printf("%i", (int)i)
CodePudding user response:
In C static variables are auto initialized.
If it's of integer number type, like
int, etc… It will be initialized to0.If it is of floating number type like
float, etc... It will be initialized to0.0.If it's of
chartype then it will be initialized with null character,\0.If it's of pointer type it will get it's default value as
NULL
