Why i can't delete this pointer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

void main(){
	char *B[100];
	
	for (int i = 0; i < 12;i ++)
	{
		B[i] = new char;
		itoa(i,B[i],10);
	}

	for (int i = 0; i< 12; i++)
	{
		delete B[i];
	}

	system("pause");

	}


May I ask why you have an array of pointers to characters then you allocate one character for some of the array? Why not just simply have an array of characters. Though, you are deleting the allocated memory.

Also, main should return int.

Anyways, I don't even think that function is supported by most compilers if any in c++.
Last edited on
I'm practicing with array of pointers
Can you show me the mistakes in this program?
Your problem is with the itoa. itoa writes a C-string into its str parameter. str must thus be an address of an array of characters. Your "array" contains exactly one character. The one allocated on previous line. One character is not an array.

Note: string "11" consumes 3 characters.
@keskiverto: Ok, I see, thanks sir
Topic archived. No new replies allowed.