/*** 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 ; Voluntarily initialized to 0, this const indicates that the pointer is pointing to a pointer of type char. //cannot become another pointer type or become a non-pointer. The address can be changed, the type cannot be changed, and this is only initialized 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