Skip to content

Instantly share code, notes, and snippets.

@deepanshululla
Created August 9, 2021 02:38
Show Gist options
  • Save deepanshululla/3cb20a6af2699b0aa420414102784834 to your computer and use it in GitHub Desktop.
Save deepanshululla/3cb20a6af2699b0aa420414102784834 to your computer and use it in GitHub Desktop.
// 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