はfirstName
部材を投入すると、セグメンテーション違反を作成し、(CONSTのchar *)を割り当てるポインタ型 - セグメンテーション障害以下
typedef struct{
const char *firstName;
const char *lastName;
}PersonDetails;
typedef struct{
const long *sinKey;
PersonDetails *value;
}Person;
、
int main(void){
....
Person *person = malloc(sizeof(Person));
const long key1 = 364222888L;
printf("Before key assignment\n");
person->sinKey = &key1;
printf("Before first name assignment\n");
person->value->firstName = "Sham";
printf("Before last name assignment\n");
person->value->lastName = "S";
....
}
、
Person
の表現であります
const char *firstName
は不変の文字列を保持します。この不変の文字列は.rodata
セクションに格納されます。 firstname
はポインティング位置を変更することができます。
しかし、以下
$ ./pq.exe
...
Before key assignment
Before first name assignment
Segmentation fault (core dumped)
どのようにこの問題を解決するために、出力のですか?
'value'は割り当てられていません... – LPs