Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void func() {
  4.     static int x = 0; // x is initialized only once across three calls of func() and
  5.                                  // the variable will get incremented three
  6.                                  //times after these calls. The final value of x will be 3.
  7.     printf("%d\n", x); // outputs the value of x
  8.     x = x + 1;
  9. }
  10.  
  11. int main() { //int argc, char *argv[] inside the main is optional in the particular program
  12.     func(); // prints 0
  13.     func(); // prints 1
  14.     func(); // prints 2
  15.     return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement