Home > Article > Backend Development > What are the return value types of functions in C++?
The return value type of a function in C defines the type of value returned after execution: Basic types: void (no return value), bool, integer, floating point, character reference type: type reference, type pointer structure or class : Type instance
The return value type of the function in C
The return value type of the function defines the value returned after the function is executed type.
Basic types
void
: Returns no value. bool
: Returns a Boolean value. int
, short
, long
): Returns an integer. float
, double
): Returns a floating point number. char
): Returns a single character. Reference type
T&
: Returns a reference to type T
. T*
: Returns a pointer to type T
. struct and class
struct
or class
name: Returns an instance of this type . Practical case
Consider a function that calculates the sum of two numbers:
// 返回两个数字的和 int add(int a, int b) { return a + b; }
The return value type of this function isint
because it returns an integer.
Here's how to use this function:
int sum = add(10, 20); // sum 将包含 30
Other notes
void
. int
. const
keyword. The above is the detailed content of What are the return value types of functions in C++?. For more information, please follow other related articles on the PHP Chinese website!