//i want create dynamic array with 3 int int *x = (int *)calloc(3, sizeof(int)); //set the first array member *x = 10; //set the sixth array member *(x+5) = 20; std::cout << *(x+5); //output: 20 the questions: is there another way to set array member? i hope i can using [] and not using arithmetic operation how can i set 6th member of array while i just set 3 in calloc and i can access it too?
5/25/2018 2:30:54 PM
Kevin AS5 Answers
New Answerofc mate, here: int* arr = new int[size]; remember to delete it afterwards when you are done with it. And you refer to it as arr[0], arr[1] etc
I do not think that zi get the question. You want to create such a thing but without new, just using one of those?
have you tried using something like that tho? int* arr = malloc(2*sizeof(int)); arr[0] = 3; arr[1] = 9; etc.. ?
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message