When printf () is called with% s, it will more or less do the following
for(i = 0; pointer[i] != '\0'; i++) { printf("%c", pointer[i]); }
What you do is something like
for(i = 0; pointer[i] != '\0'; i++) { printf("\n Element is %c", pointer[i]); }
When you reference certain elements in an array, you must use the AND index ie pointer [0], in which case 0 is an index, and the pointer is a pointer. The above for loops will move the entire array one index at a time, because āiā is the index, and āiā increases at the end of each turn of the loop, and the loop will continue to spin until it reaches the final NULL character in the array.
So, you can try something about this.
void printoutarray(char *pointertoarray) { for(i = 0; i <= 2; i++) { printf("\n Element is: %s \n", pointertoarray[i]); } }
source share