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

前端 未结 7 961
野性不改
野性不改 2020-12-03 00:50

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

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

But I just

相关标签:
7条回答
  • 2020-12-03 01:48

    If you really need the variables to stay in the scope of the loop you could write

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

    It's a bit ugly, but works.

    0 讨论(0)
提交回复
热议问题