Arizona State University (ASU) CSE100 Principles of Programming with C++ Midterm 1 Practice Exam

Question: 1 / 400

What does the keyword `static` indicate in C++?

A variable's value is reset after each function call

A class member is shared among all instances

The keyword `static` in C++ serves several purposes, one of which is to indicate that a class member is shared among all instances of that class. When a class member is declared as static, it means that there is only one copy of that member, regardless of how many objects of the class are created. Thus, all instances of the class can access and modify the same static member, leading to shared state across objects. This is particularly useful for maintaining data that should be consistent or shared across all instances, such as a counter tracking the number of objects created or a configuration setting applicable to all instances.

The other choices refer to different concepts in C++. A variable's value being reset after each function call relates to automatic storage duration, which is not what static indicates. The concept of a function not being able to return a value pertains to a specific declaration of a void function, unrelated to the static keyword. Lastly, a variable being visible only within its function pertains to scope rules, specifically for local variables, which again does not correlate with the use of the static keyword.

Get further explanation with Examzify DeepDiveBeta

A function cannot return a value

A variable is visible only within its function

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy