错误:将字符串分配给C中的char变量| 常见的C程序错误
生活随笔
收集整理的這篇文章主要介紹了
错误:将字符串分配给C中的char变量| 常见的C程序错误
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
If you assign a string to the character variable, it may cause a warning or error (in some of the compilers) or segmentation fault error occurs.
如果將字符串分配給字符變量,則可能會導致警告或錯誤(在某些編譯器中)或發生分段錯誤。
Consider the code:
考慮一下代碼:
#include <stdio.h>int main(void) {char name="Amit shukla";printf("%s",name);return 0; }Output
輸出量
Segmentation faultHow to fix?
怎么修?
Declare character array instead of char variable to assign string
聲明字符數組而不是char變量來分配字符串
char name[]="Amit shukla";翻譯自: https://www.includehelp.com/c-programs/assign-string-to-the-char-variable-in-c.aspx
總結
以上是生活随笔為你收集整理的错误:将字符串分配给C中的char变量| 常见的C程序错误的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 360影像多少钱啊?
- 下一篇: bfs广度优先搜索算法_图的广度优先搜索