I just thought I'd mention one (important) thing about that code - you're allocating an array in "classarray", but deleting it with the "delete" operator. This will create a memory leak and will most likely cause very cryptic memory errors later on. When de-allocating an array, ALWAYS use "delete[]", like this:
Also notice how I changed "x" to a pointer which is an easy way to optimize the problem mentioned by Czar Flavius above.
adress* classarray = new adress[1]; adress *x; for (int i = 0; i < 2; i++) { x = &classarray[i]; cout << x->age << "\n"; } delete[] classarray;
Also notice how I changed "x" to a pointer which is an easy way to optimize the problem mentioned by Czar Flavius above.