/*** book: "thinkinginc++" * function: Static variable inside function * Time: September 17, 2014 18:06:33* Author: cutter_point*/#include ". /require.h "#include <iostream>using namespace Std;char onechar (const char* chararray=0) { const static char* s ; Automatically initialized to 0, this const indicates that the pointer is pointing to a pointer of type char, //cannot become another pointer type or becomes a non-pointer, the address can be changed, the type cannot be changed, and this initializes only once if (Chararray) { S=chararray; The address can be arbitrarily assigned, but *s cannot be changed, and only one return *s is initialized; } else require (S, "un-initialized S"); if (*s = = ') ' return 0; return *s++;} char* a= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main () { Onechar (a); char c; while ((C=onechar ()) = 0) //back S is static or point to that place cout<<c<<endl; return 0;}
"Thinkinginc++" 52, static variables inside the function