devxlogo

Significance of const Return

Significance of const Return

Question:
What is the significance of const return type from a function?Similar to:

 const int func1();

Answer:
The const in this position guarantees that the caller of the function doesn’t change the returned value. Note that the use of const in a function’s return value is more useful when the function returns a reference or a pointer to, say an object’s data member. It’s less useful when return-by-value is used (as in your example) because the caller gets a local copy of the variable. Therefore, there’s not much point in limiting the use of the caller’s own copy.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist