小编Sur*_*rya的帖子

分段错误反转字符串文字

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

int main(void)
{
    //char s[6] = {'h','e','l','l','o','\0'};
    char *s = "hello";       
    int i=0,m;
    char temp;

    int n = strlen(s);
    //s[n] = '\0';
    while (i<(n/2))
    {
         temp = *(s+i);       //uses the null character as the temporary storage.
         *(s+i) = *(s+n-i-1);
         *(s+n-i-1) = temp;
         i++;
    }
    printf("rev string = %s\n",s);
    system("PAUSE");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在编译时,错误是分段错误(访问冲突).请告诉我们两个定义有什么区别:

char s[6] = {'h','e','l','l','o','\0'};
char *s = "hello"; 
Run Code Online (Sandbox Code Playgroud)

c

6
推荐指数
2
解决办法
1473
查看次数

指向字符串的指针存储在哪里

void main()
{
    char *p = "hello";
}
Run Code Online (Sandbox Code Playgroud)

P的存储类型和内存中的点(堆栈/数据段)是什么?字符串"helllo"存储在哪里?

c

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

执行之间的区别。script.sh 与 ./script.sh

可能的重复:
“./somescript.sh”和“. ./somescript.sh”

请阐明 shell 命令之间的区别。script.sh 与 ./script.sh 其中 script.sh 是一个 shell 脚本。

谢谢

linux

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

二进制启动后分段错误

如何调试在Linux上启动二进制文件导致的分段错误?没有源代码可用于二进制文件.

如何知道导致seg故障的二进制文件的系统调用.有没有可能有帮助的调试实用程序?

c linux debugging

0
推荐指数
2
解决办法
897
查看次数

标签 统计

c ×3

linux ×2

debugging ×1