0
Can anyone explain me this code? what is this void and this is static?
#include <stdio.h> void say_hello(); int main() { int i; for (i = 0; i < 5; i++) { say_hello(); } return 0; } void say_hello() { static int num_calls = 1; printf("Hello number %d\n", num_calls); num_calls++; }
3 ответов
+ 2
void just means, that a function of method has no return value. static is the modifier to make a class, method or variable static, which means it only exists once per run (in easy words).
+ 1
void means , function never returns any value to called function.
static is a storage class .
scope of the static variable is specified to the block it is defined .
life span is till the program ends.that means value of static variable is persists between the functions