1)
i++
increments i. You don't need to assign it to i after that... the ++ operator changes i on its own.
i = i++
is undefined behavior. it assignes i to itself, then increments it. Or it increments it, then assigns it to the original value (leaving i unchanged).
Any of the following are fine:
1 2 3 4
|
for(i = start; i <= end; ++i)
for(i = start; i <= end; i++)
for(i = start; i <= end; i = i + 1)
for(i = start; i <= end; i += 1)
| |
But what is increment? Is it always 1?
2)
What is the point of this loop:
1 2 3 4
|
for(i=start;i<=end;i=i++)
{
count=count+1;
}
| |
If the goal here is to increment 'count' by the number of items... wouldn't something like
count += end-start+1;
work? You don't even need a loop for that.
3)
What purpose does
temp
serve? You don't seem to do anything with it after you fill it. Your functions might as well not do anything. I don't know what you're using for output, but from the code you posted, you're certainly not outputting temp... which is probably why your output doesn't make sense.
4)
You should remember to delete[] whatever you new[]. You're never delete[]ing temp, so it's leaking memory with every call.