inline & constexpr Functions
🟢 Beginner
📖 Definition
inline hints to the compiler to substitute function calls inline to eliminate call-stack overhead. constexpr specifies that a function can be evaluated at compile time when passed constant expression arguments.
💡 Code Example
#include <iostream>
constexpr int cube(int x) {
return x * x * x;
}
int main() {
constexpr int result = cube(3); // Evaluated at compile time!
std::cout << "3 cubed = " << result << "\n";
return 0;
}