User Tools

Site Tools


info:c_global_local

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

info:c_global_local [2010/01/14 12:13] – created moritzinfo:c_global_local [2010/01/25 10:21] (current) – static inner vars moritz
Line 1: Line 1:
 ====== Variables in C ====== ====== Variables in C ======
  
-===== static global variables =====+===== Static global variables =====
 Test case: Code for c1.c: <code c>#include <stdio.h> Test case: Code for c1.c: <code c>#include <stdio.h>
  
Line 27: Line 27:
  
 Compile with ''gcc c2.c c1.c''. Output: ''stat.1=3, stat.2=4''. Compile with ''gcc c2.c c1.c''. Output: ''stat.1=3, stat.2=4''.
 +
 +===== Keyword Static in functions =====
 +<code c>#include <stdio.h>
 +
 +void f() {
 +    static int x;
 +    printf("%i\n", x);
 +    x = 5;
 +    return;
 +}
 +
 +
 +int main(void) {
 +    f();
 +    f();
 +    return 0;
 +}</code>
 +
 +The code prints
 +  0
 +  5
  
info/c_global_local.1263467623.txt.gz · Last modified: 2010/01/14 12:13 by moritz

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki