Increasing array size in Cpp

--

int *p, *q;p = (int *)malloc(5 * sizeof(int));p[0] = 3;
p[1] = 5;
p[2] = 7;
p[3] = 9;
p[4] = 11;
q = (int *)malloc(10 * sizeof(int));for (int i = 0; i < 5; i++){
q[i] = p[i];
}
p = q;for (int i = 0; i < 10; i++){
printf("%d ", p[i]);
}
free(q);

--

--

Gopal Katariya
Gopal Katariya

Written by Gopal Katariya

AI Engineer | Machine Learning Enthusiast | Transforming Ideas into Intelligent Solutions

No responses yet