c++: I want 2, 4, 6 to display... instead I think address numbers are displaying? -
I have to display 2, 4, 6 ... instead, I think the address number is being displayed?
What do I need to do to correct and why? Thanks
(Objective ... to display the ability to change the array space and still keep the basis of the array)
int * line; Line = new int; Line [0] = 2; Line = new int; Line [1] = 4; Line = new int; Line [2] = 6; Line = new int; Printf ("% d% d% d", line [0], line [1], line [2]);
Try instead:
int * Line; Line = new int [3]; Line [0] = 2; Line [1] = 4; Line [2] = 6; Printf ("% d% d% d", line [0], line [1], line [2]); Remove [] line; Notice points:
line = new int [3]; // Here you want to specify the size of your new array ... Delete [] row; // whenever you use the new Alto type [somevalue]; // To free allocated resources, you should remove [] later. See this question in SO too:
Comments
Post a Comment