avatar
c*e
1
void swap(int *a, int *b) {
int *c;
*c=*a;
*a=*b;
*b=*c;
return;
}
int main() {
int x=5, y=10;
swap(&x, &y);
cout << x << " " << y << endl;
return 0;
}
The correct result is printed, but there is a segmentation fault. Is it
because *c is a local variable?
avatar
k*k
2
avatar
c*e
3
void swap(int *a, int *b) {
int c;
c=*a;
*a=*b;
*b=c;
return;
}
This one is always correct. But isn't the other one only assigned a value of
*c? I do not understand why the other one causes data Segmentation fault.
Help please.
avatar
n*d
4
排气管都没在水里怎么还能开车?
avatar
c*x
5
*c没初始化

【在 c**********e 的大作中提到】
: void swap(int *a, int *b) {
: int c;
: c=*a;
: *a=*b;
: *b=c;
: return;
: }
: This one is always correct. But isn't the other one only assigned a value of
: *c? I do not understand why the other one causes data Segmentation fault.
: Help please.

avatar
l*e
6
不愧是帝都,淹得都那么厉害。
不知道在明清的时候,故宫有没有被淹过。
avatar
m*e
7
没给c分配内存啊

【在 c**********e 的大作中提到】
: void swap(int *a, int *b) {
: int c;
: c=*a;
: *a=*b;
: *b=c;
: return;
: }
: This one is always correct. But isn't the other one only assigned a value of
: *c? I do not understand why the other one causes data Segmentation fault.
: Help please.

avatar
l*r
8
应该是百年难遇吧
有几张照片太强悍了
大妈咋就没羞耻之心呢

【在 k*k 的大作中提到】
:
avatar
c*e
9
You are right. The following statement solves the problem.
int *c =new int;

【在 m******e 的大作中提到】
: 没给c分配内存啊
avatar
d*8
10
从明朝算起,有5、6百年了,故宫该淹5、6次啦,不知道史书上有没有记载

【在 l*******r 的大作中提到】
: 应该是百年难遇吧
: 有几张照片太强悍了
: 大妈咋就没羞耻之心呢

avatar
l*r
11
那就500年一遇,呵呵

【在 d*******8 的大作中提到】
: 从明朝算起,有5、6百年了,故宫该淹5、6次啦,不知道史书上有没有记载
avatar
r*e
12
这个保险套的用法不错,就是很容易扎破

【在 k*k 的大作中提到】
:
avatar
i*a
13
so maybe I should cancel my trip to beijing this fall...

【在 k*k 的大作中提到】
:
avatar
k*e
14
This fall, you won't get rain. You will get sand instead ..

【在 i****a 的大作中提到】
: so maybe I should cancel my trip to beijing this fall...
avatar
i*a
15
but every where may still be dirty and muddy after the flood

【在 k****e 的大作中提到】
: This fall, you won't get rain. You will get sand instead ..
avatar
k*k
16
有经验的来说说,那个大妈用wsj是防洪呢还是生理需要?
avatar
m*d
17
不会,春天才沙呢,秋天是帝都最好的季节

【在 k****e 的大作中提到】
: This fall, you won't get rain. You will get sand instead ..
avatar
c*6
18
卫生巾上有血

【在 k*k 的大作中提到】
: 有经验的来说说,那个大妈用wsj是防洪呢还是生理需要?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。