Saturday, May 22, 2010

C++ questions?

from my book... just studying


two more... so im looking... since i now know the pointer it wants an array i believe...


code gets the best answer... explain it to me too








1. Write the statement, which dynamically creates a new array of integers. The number of elements for this array should be 'numbers'. The address of this new array should be assigned to pointer variable 'd_address'.


Assume that 'd_address' is already declared.














2. Rewrite the following in pointer notation. Use the simplest form, assuming that this call is not part of a loop; in other words, do not include a counter which would reach the zero element:


array[0] -

C++ questions?
1) use the "new" keyword to dynamically create arrays in C++ (they didn't have this in C). The pointer to this array of integers is assigned to d_address.


d_address = new int[numbers];





2) array[0] is the first element of the array, which is exactly where the pointer to this array is pointing. The equivalent form with pointers is


*array


(assuming the elements are 1 byte each, then array[1] would be *(array+1), array[2] is *(array+2), etc.)


No comments:

Post a Comment