#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int b;
printf("hello");
for(b=1;b<=100;++b)
{
if(b%10==1){
cout << "\n";
for(int l=0;l<=100;++l)
cout << "-" ;
cout << endl;
}
printf("|%s|",b);
}
return 0;
}
printf放在循环体外面工作正常,但放在循环体中的那个会在运行时出现某种错误!看看图片!
答案 0 :(得分:1)
您的b
是int
你给b
,其中printf()需要一个指向char的指针,并试图取消引用你给出的值。
由于您通过b
提供的值不是指向任何内容的有效指针,因此您的程序存在一些访问问题。