C static variables and intialization

Posted by yCalleecharan on Stack Overflow See other posts from Stack Overflow or by yCalleecharan
Published on 2010-04-11T13:44:48Z Indexed on 2010/04/11 13:53 UTC
Read the original article Hit count: 202

Filed under:
|
|

Hi, If I have a global static variable x like in this code

 #include <stdio.h>
 #include <stdio.h>

 static int x;

 int main(void)
 {

 DO SOMETHING WITH x HERE

 x++;

 }

What will be difference if I opted to initialize x to a value first say as in

static int x = 0;  

before entering "main"?

In my first case where I didn't assign a value to x, does the compiler implicitly know that x is to be set to zero as it's a static variable? I heard that we can do this with static variables.

Thanks a lot...

© Stack Overflow or respective owner

Related posts about c

    Related posts about static