Machine-translated by Google. Questions are authored in English.
Top

Discussion

Can variable i be accessed by functions in another source file?

int i;
    int main()
    {
        printf("%d\n", i);
    }

 

  • A.false
  • B.Only if static keyword is used
  • C.Depends on the type of the variable
  • D.true

Answer: D

Correct answer: true

A variable at file scope has external linkage by default, so another source file can reach it by declaring extern int i;. Adding static to the definition is what would prevent that.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.