由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
CS版 - Help for C language
相关主题
问一个简单的C的问题大家看看我这个C++ STL Functor那里写错了
C里面的动态数组是放在栈里还是堆里?STL map变量的实际memory usage估算 (转载)
一个程序的小问题C++(非VC++) 删除链表时如何对指针操作? 在线等回复!谢谢!
One question about Void pointer (转载)求教:data structure 经典入门书籍
how to define variables on commnad line in C++sorting问题求教。 (转载)
问一个C++下计时的问题高人指点怎么在embedded sys(atmel 系列)上写内存管理
Two interview questions? (转载)Valgrind报uninitialized value was created by a heap allocat (转载)
出题了! std::copy()在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的设计?
相关话题的讨论汇总
话题: struct话题: number话题: language话题: program话题: include
进入CS版参与讨论
1 (共1页)
q*****z
发帖数: 191
1
Can anyone tell me what is wrong with this little C program? I am learning it
how to pass structure pointer back and forth in functions. This program compil
es ok but when excuting it, it cannot give me the right result. Thanks in adva
nce.
Here is the program:
#include
#include
struct number{
double r;
double c;
};
struct number *addtwocom(struct number *a, struct number *b)
{
struct number *c;
c->r = a->r+b->r;
c->c = a->c+b->c;
re
t*s
发帖数: 1504
2
your variable c is just a pointer
you need to use malloc(sizeof(number)) to allocate space first

【在 q*****z 的大作中提到】
: Can anyone tell me what is wrong with this little C program? I am learning it
: how to pass structure pointer back and forth in functions. This program compil
: es ok but when excuting it, it cannot give me the right result. Thanks in adva
: nce.
: Here is the program:
: #include
: #include
: struct number{
: double r;
: double c;

f***h
发帖数: 52
3
yes
warning C4700: local variable 'c' used without having been
initialized
warning C4700: local variable 'a' used without having been
initialized
warning C4700: local variable 'b' used without having been
initialized
add this line after each declaration.
a=(struct number *)malloc(sizeof(struct number));

【在 t*s 的大作中提到】
: your variable c is just a pointer
: you need to use malloc(sizeof(number)) to allocate space first

1 (共1页)
进入CS版参与讨论
相关主题
在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的设计?how to define variables on commnad line in C++
google interview, text mining (转载)问一个C++下计时的问题
求教:多个有序数组怎么合并最快? (转载)Two interview questions? (转载)
帮看看这段code (转载)出题了! std::copy()
问一个简单的C的问题大家看看我这个C++ STL Functor那里写错了
C里面的动态数组是放在栈里还是堆里?STL map变量的实际memory usage估算 (转载)
一个程序的小问题C++(非VC++) 删除链表时如何对指针操作? 在线等回复!谢谢!
One question about Void pointer (转载)求教:data structure 经典入门书籍
相关话题的讨论汇总
话题: struct话题: number话题: language话题: program话题: include