🎴 Flashcard Mode

C#, Java, and C++ Programming Concepts

Card1 / 20
Mastered0
Review0
QuestionClick to flip

I have a function declaration like this(in C/C++).const int f(int* a){ ..... // Do something here return *a; }what is the purpose of the keyword const here?

AnswerClick to flip back
A
Prevents the compiler from assigning the function as an lvalue
💡 Explanation:

The const keyword before a function's return type (const int f(...)) prevents the function result from being used as an lvalue - you cannot assign to it. This means expressions like f() = 5 would be compile errors. The const refers to the return value being treated as read-only, not that it cannot be modified by others (option D is misleading - the returned value can still be modified if it's a reference/pointer).

Change Mode