What keyword is used to define a new function in C++?

Prepare for the ASU CSE100 Programming Exam with C++ Study Guide. Review flashcards, multiple choice questions, with hints and explanations. Master your exam!

The keyword used to define a new function in C++ is "void" when you are indicating that the function does not return a value. In C++, when defining a function, you need to specify the return type of the function, which indicates what kind of data the function is expected to return to the caller.

Using "void" as the return type signifies that the function will perform its tasks but will not return any value. For example:


void myFunction() {

// Code for the function

}

In this case, "myFunction" is a function that performs some operations but does not give any value back at the end. If you wanted to define a function that does return a value, you would use an appropriate data type (like int, double, float, etc.) instead of "void."

The other terms, like "function" and "method," are not keywords in C++. "def" is used in Python for defining functions, and those terms may refer to concepts in different programming languages or be informal terms used to describe functions. However, in the C++ context, "void" and other data types are what you use to define functions correctly.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy