相关疑难解决方法(0)

char s []和char*s有什么区别?

在C中,可以在声明中使用字符串文字,如下所示:

char s[] = "hello";
Run Code Online (Sandbox Code Playgroud)

或者像这样:

char *s = "hello";
Run Code Online (Sandbox Code Playgroud)

那么区别是什么呢?我想知道在编译和运行时的存储持续时间实际发生了什么.

c string constants char

495
推荐指数
6
解决办法
33万
查看次数

为什么需要.bss段?

我所知道的是全局和静态变量存储在.data段中,未初始化的数据存在于.bss段中.我不明白的是为什么我们有未初始化变量的专用段?如果未初始化的变量在运行时分配了值,那么该变量是否仅存在于.bss段中?

在以下程序中, a是在.data段中,并且b.bss段中; 那是对的吗?如果我的理解是错误的,请纠正我.

#include <stdio.h>
#include <stdlib.h>

int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9};
int b[20]; /* Uninitialized, so in the .bss and will not occupy space for 20 * sizeof (int) */

int main ()
{
   ;
}  
Run Code Online (Sandbox Code Playgroud)

另外,请考虑以下程序,

#include <stdio.h>
#include <stdlib.h>
int var[10];  /* Uninitialized so in .bss */
int main ()
{
   var[0] = 20  /* …
Run Code Online (Sandbox Code Playgroud)

c linux compiler-construction

107
推荐指数
6
解决办法
4万
查看次数

标签 统计

c ×2

char ×1

compiler-construction ×1

constants ×1

linux ×1

string ×1