fork download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. int size;
  6. int* array = new int[size](); // array of 0-initialized ints
  7.  
  8. A(int array_size = 10) : size(array_size) {}
  9.  
  10. ~A() { delete [] array; }
  11. };
  12.  
  13. void show_data(const A& a)
  14. {
  15. std::cout << "For object of type 'A' at address " << &a ;
  16. std::cout << "\n\tsize = " << a.size;
  17. std::cout << "\n\tarray = " << a.array;
  18. std::cout << "\n\tarray contents:\n";
  19.  
  20. for (unsigned i = 0; i < a.size; ++i)
  21. std::cout << "\t\t" << i << ": " << a.array[i] << '\n';
  22.  
  23. std::cout << '\n';
  24. }
  25.  
  26. int main()
  27. {
  28. A a;
  29. show_data(a);
  30.  
  31. A b(5);
  32. show_data(b);
  33. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
For object of type 'A' at address 0xbfc77730
	size = 10
	array = 0x8d4e008
	array contents:
		0: 0
		1: 0
		2: 0
		3: 0
		4: 0
		5: 0
		6: 0
		7: 0
		8: 0
		9: 0

For object of type 'A' at address 0xbfc77738
	size = 5
	array = 0x8d4e038
	array contents:
		0: 0
		1: 0
		2: 0
		3: 0
		4: 0