Assuming I have this array of string
char* arr[] = {"Me", "you", "Now", NULL};
My aim is to remove "Me" so that the resultant array is:
arr = {"you", "Now", NULL};
Is there a way I can do this without running a for
loop and store the element in a new array?
I have tried increment operation arr++
, but I am getting error.
The size of the array can not be changed. And arrays are non-modifiable lvalues. They do not have the assignment operator
So this statement
is incorrect.
What you can do is to move elements of the array to the left. For example
Here is a demonstration program.
The program output is
Pay attention to that the arrays still have four elements.