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

前端 未结 7 1004
野性不改
野性不改 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:27

    According to http://linuxsoftware.co.nz/cppgrammar.html#for-init-statement you can get only simple declaration or an expression (which is not permitted to contain declaration) in the for-init statement. That means the answer is no (if I analyzed the BNF correctly :) )

提交回复
热议问题