Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <new>
- using namespace std;
- template<typename Type, size_t Size>
- void print_size(Type (&array)[Size]) {
- cout << "size of array: " << Size << '\n';
- }
- int main() {
- int static_array[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
- int* dynamic_array = new int[10]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- for(int e : static_array) {
- cout << e << ' ';
- }
- cout << '\n';
- // using range-for loop is impossible on dynamic arrays (http://bit.ly/1gBhmPF)
- // for(int e : dynamic_array) {
- // cout << e << '\t';
- // }
- print_size(static_array);
- // type of dynamic_array is not array (std::is_array<decltype(dynamic_array)>::value == false)
- // print_size(dynamic_array);
- // sizeof array
- cout << "sizeof static array: " << sizeof static_array << '\n';
- // sizeof pointer
- cout << "sizeof dynamic array: " << sizeof dynamic_array << '\n';
- delete[] dynamic_array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement