Created
August 9, 2021 02:38
-
-
Save deepanshululla/3cb20a6af2699b0aa420414102784834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Type your code here, or load an example. | |
#include <string> | |
#include <iostream> | |
using namespace std; | |
template<typename T, size_t N> | |
constexpr size_t arraySize(T (&)[N]) noexcept { | |
return N; | |
} | |
int main() { | |
char b[] = "hello"; | |
// runtime computation of size of an array | |
cout << to_string(sizeof(b)) << endl;//6 | |
// compile time computatin of size of an array | |
cout << to_string(arraySize(b)) << endl;//6 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment