Q:

Isn't it ok in terms of memory leakage etc

It's been about 2 months since I started to learn c++ and I'm not quite sure about I'm doing wrong for my project. I have a dynamically allocated array with an initial size and after I want to change the size of it. The thing I wonder is why the following code is wrong
    int *firstPtr = new int [4];
    for (int i = 0; i < 4; i++) {
        firstPtr[i] = i;
    }

    int *tempPtr = new int[5];
    for (int i = 0; i < 4; i++) {
        tempPtr[i] = firstPtr[i];
    }
    tempPtr[4] = 4;
   // firstPtr = new int[5];
    firstPtr = tempPtr;
    delete tempPtr;

     for (int i = 0; i < 5; i++) {
        cout << firstPtr[i] << endl;
    }

because the output is: 
10757752 
10753936 
2 
3 
4

PS: I can't use realloc/malloc etc for this since the project is just about pointers. How can I correct this without them. 

A:

firstPtr = tempPtr;

first Ptr now points to the same memory as tempPtr.
delete tempPtr;

You are now deleting that memory, the same memory both firstPtr and tempPtr are pointing to.
for (int i = 0; i < 5; i++) {
    cout << firstPtr[i] << endl;
}

You are accessing deleted memory, the values printed can be anything.
To get what I'm assuming you want, you need to remove the line
firstPtr = tempPtr;

or delete the memory after the for:
for (int i = 0; i < 5; i++) {
    cout << firstPtr[i] << endl;
}
delete[] tempPtr;

Note that in the second case you will get a memory leak, since the memory initially pointed to by firstPtr is no longer accessible.
A complete working and correct code would be as follows:
int *firstPtr = new int [4];
for (int i = 0; i < 4; i++) {
    firstPtr[i] = i;
}

int *tempPtr = new int[5];
for (int i = 0; i < 4; i++) {
    tempPtr[i] = firstPtr[i];
}
tempPtr[4] = 4;

for (int i = 0; i < 5; i++) {
    cout << firstPtr[i] << endl;
}
delete[] tempPtr;
delete[] firstPtr;

Some ASCII art:
firstPtr = new int[4];

firstPtr
   |
+------++------++------++------+
|      ||      ||      ||      |
|      ||      ||      ||      |
+------++------++------++------+

for (int i = 0; i < 4; i++) {
    firstPtr[i] = i;
}

firstPtr
   |
+------++------++------++------+
|   0  ||   1  ||   2  ||   3  |
|      ||      ||      ||      |
+------++------++------++------+

int *tempPtr = new int[5];
    for (int i = 0; i < 4; i++) {
        tempPtr[i] = firstPtr[i];
    }
    tempPtr[4] = 4;

tempPtr
   |
+------++------++------++------++------+
|   0  ||   1  ||   2  ||   3  ||   4  |
|      ||      ||      ||      ||      |
+------++------++------++------++------+

So now, in memory, you have:
firstPtr
   |
+------++------++------++------+
|   0  ||   1  ||   2  ||   3  |
|      ||      ||      ||      |
+------++------++------++------+

tempPtr
   |
+------++------++------++------++------+
|   0  ||   1  ||   2  ||   3  ||   4  |
|      ||      ||      ||      ||      |
+------++------++------++------++------+

Your next line:
firstPtr = tempPtr;

does this:
no longer pointed to by firstPtr
   |
+------++------++------++------+
|   0  ||   1  ||   2  ||   3  |
|      ||      ||      ||      |
+------++------++------++------+

tempPtr
firstPtr  -  firstPtr now points here
   |
+------++------++------++------++------+
|   0  ||   1  ||   2  ||   3  ||   4  |
|      ||      ||      ||      ||      |
+------++------++------++------++------+

delete tempPtr;

tempPtr
firstPtr  -  firstPtr now points here
   |
+------++------++------++------++------+
|   x  ||   x  ||   x  ||   x  ||   x  |
|      ||      ||      ||      ||      |
+------++------++------++------++------+

So now, tempPtr points to delete memory. Hope this clears things up.

