MCPcopy Create free account
hub / github.com/andreasfertig/programming-with-cpp20 / StrLen

Function StrLen

12.02-constexprStrlenCpp111/main.cpp:7–11  ·  view source on GitHub ↗

#A Define a constexpr function

Source from the content-addressed store, hash-verified

5
6// #A Define a constexpr function
7constexpr size_t StrLen(const char* str)
8{
9 // #B Use a single return and recursion with the ternary operator
10 return *str ? 1 + StrLen(str + 1) : 0;
11}
12
13int main()
14{

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected