我有一个名为 Shop 的数据库,其中包含 3 个表:
create table usr(
id_usr varchar(20) not null,
primary key(id_usr)
);
create table product(
id_product varchar(20) not null,
id_size varchar(20) not null,
price float(4,2) unsigned,
primary key(id_product,id_size)
);
create table cart(
myUser varchar(20),
mySize varchar(20),
product varchar(20),
qty int not null,
primary key(myUser,product,mySize),
FOREIGN KEY (myUser) REFERENCES usr (id_usr),
FOREIGN KEY (product) REFERENCES product (id_product),
FOREIGN KEY (mySize) REFERENCES product (id_size)
);
Run Code Online (Sandbox Code Playgroud)
当我在 sql 中编译时,它给了我这条消息:
如果我尝试删除外键 mySize (FOREIGN KEY (mySize) REFERENCES prodotto (id_size)) …
mysql sql foreign-keys composite-primary-key mysql-error-1005
此代码产生分段错误:
int main(int argc, char *argv[]){
int *n;
*n = atoi(argv[1]);
printf("n: %d \n", *n);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
虽然这有效:
int main(int argc, char *argv[]){
int *n;
*n = atoi(argv[1]);
pid_t pid = fork();
if (pid == 0)
return 0;
else
printf("n: %d \n", *n);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么第二个用叉子工作?我知道之后int *n,我应该为inta 分配空间malloc(),但是使用fork()似乎自动执行此操作.
编辑:现在我理解未定义的行为:)但现在我问:在这个特定情况下是什么原因?
这两个代码必须更改字符2中的char'4'
int main(int argc, char *argv[]){
char *s = "hello";
*(s+2)='4';
printf( "%s\n",s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我运行这个时,我运行时会出现分段错误:
int main(int argc, char *argv[]){
char *s = argv[1];
*(s+2)='4';
printf( "%s\n",s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我知道还有其他方法可以做到这一点.两个程序有什么区别?
int main(int argc, char *argv[]) {
char *s = argv[1];
*(s + (strlen(argv[1]))) = argv[2];
printf("%s \n", s);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我跑步时:./concat hello, world输出是:
hello,Mworld我期待
hello,world
什么是M炭?为什么C把这个?