我有这个代码:
#include<stdio.h>
int main()
{
int a=10;
switch(a)
{
case '1':
printf("ONE\n");
break;
case '2':
printf("TWO\n");
break;
defalut:
printf("NONE\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该程序不打印任何东西,甚至不打印NONE.我发现default有一个错字defalut!
我想知道为什么编译器没有检测到这种语法错误.
我有这个代码可以解决这个问题:
#include <stdio.h>
int main()
{
int a = 30000, b = 20,sum;
char *p;
p=(char *)a;
sum = (int)&p[b]; // adding a & b
printf("%d",sum);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下代码中发生了什么吗?
p = (char*)a;
sum = (int)&p[b]; // adding a & b
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出hello-err hello-err hello-err hello-err hello-err hello-err
间隔为1秒.我想知道为什么hello-out永远不会被打印出来.
我现在想要如何分割字符串,
44664212666666 into [44664212 , 666666]无论
58834888888888 into [58834, 888888888]
是否知道最后一个重复数字出现的位置.所以将它传递给函数说seperate(str)- >[non_recurring_part, end_recurring digits]