How do I declare several variables in a for (;;) loop in C?

Viewed 56332

I thought one could declare several variables in a for loop:

for (int i = 0, char* ptr = bam; i < 10; i++) { ... }

But I just found out that this is not possible. GCC gives the following error:

error: expected unqualified-id before 'char'

Is it really true that you can't declare variables of different types in a for loop?

7 Answers

You can also do:

for (int i = 0; i < 10; i++) {
    static char* ptr = bam;
}
Related