If the data is static, how can you access that data in another file ?
-
Hello Question : Differentiate static and extern ? If the data is static, how can you access that data in another file ? My answer is : The static keyword allows a variable to maintain its value among different function calls. Extern says the variable, or function, is defined outside this source file. main.h -------- #include <> static int x; main.c -------- #include "main.h" int main(void) { printf("\n x is %d", x); return 0; } My answer is sufficient or partially or wrong ...? Give me an advise ? Thanking you.
-
Hello Question : Differentiate static and extern ? If the data is static, how can you access that data in another file ? My answer is : The static keyword allows a variable to maintain its value among different function calls. Extern says the variable, or function, is defined outside this source file. main.h -------- #include <> static int x; main.c -------- #include "main.h" int main(void) { printf("\n x is %d", x); return 0; } My answer is sufficient or partially or wrong ...? Give me an advise ? Thanking you.
its partially correct. 'static' has multiple meanings. you've mentioned one, but there is another meaning that is more closely related to 'extern'.
-
its partially correct. 'static' has multiple meanings. you've mentioned one, but there is another meaning that is more closely related to 'extern'.
Could you elaborate it , please?
-
Could you elaborate it , please?