1.

How will you use a variable defined in source file1 inside source file2?

Answer»

We can achieve this by making USE of the “extern” KEYBOARD. It ALLOWS the variable to be accessible from one file to another. This can be handled more cleanly by creating a header file that just CONSISTS of extern variable declarations. This header file is then included in the source files which uses the extern variables. Consider an example where we have a header file named variables.h and a source file named sc_file.c.

/* variables.h*/extern int global_variable_x;/* sc_file.c*/#include "variables.h" /* Header variables included */#include <stdio.h>VOID demoFunction(void){ printf("Value of Global Variable X: %d\n", global_variable_x++);}


Discussion

No Comment Found