我有這個代碼
char *c="hello";
char *x=malloc(sizeof(char)*5 1);
memcpy(x,(char[2])c,sizeof("hello") 1);
x[5]='\0';
printf("%s\n",x);
它給出了強制轉換指定陣列型別的錯誤。這是為什么?這個錯誤背后的原因是什么。這是否意味著I can't cast like with array type meaning:I can cast to pointer like (char *) but I can't cast to array type like (char[2]) or (char[])我錯過了什么?
我需要在我的代碼中做什么來解決錯誤強制轉換指定的陣列型別錯誤
10 | memcpy(x,(char[2])c,sizeof("hello") 1);
uj5u.com熱心網友回復:
陣列沒有賦值運算子。例如,您可能不會寫
char *c="hello";
char s[6];
s = c;
結果這樣的鑄造像
( char[6] )c
不被允許。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/359886.html
上一篇:為什么我的代碼沒有輸入地址?
