【发布时间】:2020-05-15 20:22:04
【问题描述】:
您好,我是 C 的初学者,当我遇到这个问题时,我正在使用结构:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char nom[20];
char prenom[20];
int note;
} Etu;
int main() {
Etu E[5];
E[0].nom = "reda";
printf("%s", E[0].nom);
return 0;
}
有了这个我有这个错误(error: assignment to expression with array type)。所以我决定用指针来做,它实际上是我使用的代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char *nom;
char *prenom;
int note;
} Etu;
int main() {
Etu E[5];
E[0].nom = "reda";
printf("%s", E[0].nom);
return 0;
}
所以问题是它们之间有什么区别,因为字符串是指针。 谢谢你..
【问题讨论】:
-
这可能已经在 SO...
-
“因为字符串是指针”。这不是一个正确的假设。
标签: c