For a homework assignment, I am not allowed to use any variables like “int i = 0;” — only pointers.
The problem is that I need to do something n times — let’s say 10 times — but I can’t figure out a way to do this said things n times without a for loop. It is manipulating a pointer to integer, and it is not terminated by zero, but the size is always the same (lets say 10).
Is there a way to do the following operation without using an integer to control the loop?
int i;
for (i = 0; i < 10; i++) {
*(p + i) = 0;
}
Maybe like this:
UPDATE:
Doing this you would avoid using integers by just identifying a beginning (p) and an end (p + 10) and then just iterating over them.
It doesn’t apply to this particular case but many times you don’t know (or need to know) the size of an array.