We can write it as:

 

            y = &x[0];         

In the above statement, we get the address of the fist location of the array x and store it in y. As y is lvalue, so it can be used on left hand side. This means that the above statement is correct.

 

            y = x;

 

Similarly, the statement y = x is  also correct. x is an array of six elements that holds the address of the first element. But we cannot change this address. However we can get that address and store it in some other variable. As y is a pointer variable and lvalue so the above operation is legal. We have dynamically allocated the memory for the array. This memory, after the use, can be released so that other programs can use it. We can use the delete keyword to release the memory. The syntax is:

 

            delete[ ] y;

 

We are releasing the memory, making it available for use by other programs. We will not do it in case of x array, as ‘new’ was not used for its creation. So it is not our responsibility to delete x.

 

BACK

HOME

NEXT