Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++

Get more with Examzify Plus

Remove ads, unlock favorites, save progress, and access premium tools across devices.

FavoritesSave progressAd-free
From $9.99Learn more

1 / 565

How can global variables be accessed across different files?

By using the static keyword.

By declaring them with extern in the other file.

Global variables are defined outside of a function and can be accessed by all functions within a file. To access them across different files, the keyword "extern" must be used in the other file. This tells the compiler that the variable is declared in another file and can be accessed. Option A is incorrect because the static keyword restricts the variable's scope to the file it is defined in. Option C is incorrect because redefining the global variable in each file can cause conflicts and may lead to unexpected results. Option D is also incorrect because including the file where the variables are defined will only allow access within that particular file.

Get further explanation with Examzify DeepDiveBeta

By redefining them in each file.

By including the file where they are defined.

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy