小编Sou*_*osh的帖子

%d是什么意思?为什么d而不是另一封信?

我刚刚开始学习C并想问一些非常基本的问题.我根本没有任何编程背景.我只是在教程的开头(http://www.cprogramming.com/tutorial/c-tutorial.html),并且有些事情没有解释.例如,在下面的介绍性简单程序中......

问题:为什么他使用"%d" - 为什么d而不是另一封信?我理解%是模数操作数,意思是余数,但为什么d?据我所知,stdio.h导入了一个要使用的术语库/术语表,比如printf等......是不是和%d相同?:

#include <stdio.h>

int main()
{
    int this_is_a_number;

    printf( "Please enter a number: " );
    scanf( "%d", &this_is_a_number );
    printf( "You entered %d", this_is_a_number );
    getchar();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c printf c-strings

-5
推荐指数
1
解决办法
2万
查看次数

指针如何分配内存

#include<stdio.h>
int main()
{

  char *str;

  gets(str);

  puts(str);

return 0;
}
Run Code Online (Sandbox Code Playgroud)

output =分段错误

为什么它会给出分段错误?

c pointers gets segmentation-fault

-5
推荐指数
1
解决办法
96
查看次数

堆栈内存"泄漏"在C中

考虑以下代码段:

void f() {
    int arr[10];
    arr = malloc(sizeof(int) * 100);
    for (int i = 0 ; i < 100 ; i++) {
        printf("%d ", arr[i]);
    }
    puts("");
    free(arr);
}
Run Code Online (Sandbox Code Playgroud)

arr[10]当函数f返回时,是否会释放原始堆栈内存?(或者这是堆栈内存泄漏?)

c memory-leaks memory-management

-5
推荐指数
1
解决办法
348
查看次数

break语句在循环中不起作用

我看到一个教程,解释如何在循环中使用"break"语句,但每次我尝试使用它时,我收到编译错误说:

"break语句不在循环或开关内
                       break;"

这是我的代码:

if (finalFirstChar > 6 || finalFirstChar < 1)
{
    printf("You didn't entered a proper number! \n");
    break;
}
Run Code Online (Sandbox Code Playgroud)

c loops if-statement break

-5
推荐指数
1
解决办法
823
查看次数

为什么类型转换从int打印"0.0000"

下面是我为了解类型转换而编写的一些代码,但我不明白为什么浮点数或双精度值的值打印为"0.000000",即使我从整数数组中输入或尝试从联合的地址解释.

#include <stdio.h>

union test1
{
 int x;
 float y;
 double z;
};


int main()
{
 int x[2]={200,300};
 float *f;
 f=(float*)(x);
 printf("%f\n",*f); /*(1)why is this value 0.0*/

 *f=(float)(x[0]); /*(2)this works as expected and prints 200.00000*/
  printf("%f\n",*f);

  union test1 u;
  u.x=200;
  /*(3)this line give compilation error why*/
  //printf ("sizeof(test1) = %d \n", sizeof(test1));
  /*(4) this line also prints the value of float and double as 0.0000 why*/
  printf ("sizeof(test1) = %lu u.x:%d u.y:%f u.z:%lf \n", sizeof(u), u.x, u.y, u.z);
  return 0; …
Run Code Online (Sandbox Code Playgroud)

c pointers casting sizeof

-5
推荐指数
1
解决办法
409
查看次数

在一起编写时如何解析/评估两个单独的运算符?

背后真的发生了什么?

int a=10,b=5,c=3;
b!=!a;
c=!!a;
Run Code Online (Sandbox Code Playgroud)

为什么值bc分别为5和1?

c

-5
推荐指数
1
解决办法
52
查看次数

C++为什么make new int是错误的?

为什么我的代码错误?

int *x ;
x = new int[5];
x[0] = 3;
x[1] = 4;
x[2] = 5;
x[3] = 1;
x[4] = 2;
x[5] = 11;
x[6] = 90;
int *y ;
y = new int[5];
cout << "if no error, then this command should be run" << endl;
Run Code Online (Sandbox Code Playgroud)

但输出是:

进程在0.07883秒后退出,返回值为3221226356

按任意键继续 ...

c++ arrays pointers

-6
推荐指数
1
解决办法
304
查看次数

有什么神秘的事情发生?

我有一个与此代码相关的问题.

 #include <stdio.h>
 void main() 
 {
        char array[0];
        scanf("%s", array);
        printf("%s", array);
        return;
 } 
Run Code Online (Sandbox Code Playgroud)

当我在输入字段中输入数据时,它会在数组中存储并获得输出,但它的大小为0.

另一件事情是,当我输入假设'a'12次然后以某种方式控制到达scanf()接受输入并再次进入'a'再次12次控制到达scanf()并继续直到我输入少于12个字符.

如果输入超过12个字符,程序崩溃.

为什么会这样?

c arrays

-6
推荐指数
1
解决办法
92
查看次数

在C中读取一个字符串

我想读一个名字并打印出来.但是控件不会等我输入名称并直接打印出一些无意义的字符输出.

#include <stdio.h>
using namespace std;

int main() {
    char name[20];
    printf("Enter name: ");
    scanf("%s", name);
    printf("Your name is %s", name);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这里有什么错误吗?

c

-6
推荐指数
1
解决办法
99
查看次数

如何知道循环如何结束

在编写程序时,我遇到了一个奇怪的情况.我需要知道一个for loop是正常结束还是正常结束break.有没有办法知道这个?

java for-loop break

-7
推荐指数
1
解决办法
496
查看次数