Ask Question
24 September, 12:18

Consider the following 3 programs:

1

//contents of file foo. c:

static int a = 5;

int main () {

f ();

return 0;

}

//contents of file bar. c:

static int a = 10;

void f () {

printf ("%d/n", a);

}

2

//contents of file foo. c:

int a = 5; int main () {

f ();

return 0;

}

//contents of file bar. c:

void f () { int a = 10;

printf ("%d/n", a);

}

3

//contents of file foo. c:

int a = 5;

int main () {

f (); return 0;

}

//contents of file bar. c:

int a;

void main () {

printf ("%d/n", a);

}

If the command "gcc foo. c bar. c" is executed, which of the above programs result in a linker error?

+4
Answers (1)
  1. 24 September, 13:23
    0
    If the following programs are executed then Program 2 results "linker error"

    Explanation:

    Because In program 1, which is in the C Programming Language they declare the integer data type variable "a" as static in both files, so the scope of the static member is in the file or method then, the output of the following Program 1 is 10.

    In the Program 2, which is in the C Programming Language they declare the integer data type variable in both files with initialization of 5 and 10, so when they execute the following Program 2 then, it occurs an "linker error" because the following program cannot find the value of the integer variable a.

    In the Program 3, which is in the C Programming Language they declare the integer data type variable in both files but they initialize in the file "foo. c" is 5 and not initialize in the file "bar. c", so when they execute the following Program 3 then, its output is 5.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Consider the following 3 programs: 1 //contents of file foo. c: static int a = 5; int main () { f (); return 0; } //contents of file bar. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers