Variables which have static storage allocation are default initialized to zero. Therefore, the following statements are effectively equivalent.
static circular_queue *cir;
// equivalent to
static circular_queue *cir = 0;
// equivalent to
static circular_queue *cir = NULL;
The variable cir
has function scope, i.e., it can be accessed only in the function get_char
. Therefore, the answer to your question
I would like to return a function with a variable inside it that I can initialize inside the function that returns it. Possible, or no?
is no. You need a global variable which is visible to both the functions get_char
and generate_get_char
. Also, note that a function name implicitly converts to a pointer. Therefore, the following are equivalent -
return &get_char;
// equivalent to
return get_char;