小编ins*_*ane的帖子

切换条件下的默认情况

我有这个代码:

  #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!
我想知道为什么编译器没有检测到这种语法错误.

c

27
推荐指数
3
解决办法
1659
查看次数

不使用+添加两个数字

我有这个代码可以解决这个问题:

#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)

c pointers

19
推荐指数
3
解决办法
981
查看次数

为什么使用fprintf时打印到stdout不会发生?

我有这个代码:

#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永远不会被打印出来.

c printf stdout stderr

16
推荐指数
1
解决办法
7285
查看次数

拆分数字模式

我现在想要如何分割字符串, 44664212666666 into [44664212 , 666666]无论 58834888888888 into [58834, 888888888] 是否知道最后一个重复数字出现的位置.所以将它传递给函数说seperate(str)- >[non_recurring_part, end_recurring digits]

python string algorithm

0
推荐指数
1
解决办法
118
查看次数

标签 统计

c ×3

algorithm ×1

pointers ×1

printf ×1

python ×1

stderr ×1

stdout ×1

string ×1