动态数组和链表的区别是否仅仅在于内存地址的连续性?

蓝鹰 2011-09-18 05:17:06
动态数组:
int *a=(int *)malloc(n*sizeof(int));
链表:
typedef struct node{
int data;
struct node *next;
}slnode;


能否从这个角度解释一下: 既然后面有了sizeof(int),那么这个(int *)究竟是何意?
...全文
232 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
蓝鹰 2011-09-19
  • 打赏
  • 举报
回复
大家继续啊!
AnYidan 2011-09-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jake443403168 的回复:]
malloc返回的是一个(void*) 赋值给int*当然要转换一下
[/Quote]

++
贝隆 2011-09-18
  • 打赏
  • 举报
回复
我认为时
老邓 2011-09-18
  • 打赏
  • 举报
回复
sizeof取操作对象在内存中的大小
(int *)是类型强制转换
楼主补一下基本功吧。
Ol_lO 2011-09-18
  • 打赏
  • 举报
回复
void *malloc( size_t size );

size:Bytes to allocate


malloc returns a void pointer to the allocated space, or NULL if there is insufficient memory available. To return a pointer to a type other than void, use a type cast on the return value. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. If size is 0, malloc allocates a zero-length item in the heap and returns a valid pointer to that item. Always check the return from malloc, even if the amount of memory requested is small.

ryfdizuo 2011-09-18
  • 打赏
  • 举报
回复
1楼正解, 右键转到定义函数定义,看看malloc的定义。
Jake443403168 2011-09-18
  • 打赏
  • 举报
回复
malloc返回的是一个(void*) 赋值给int*当然要转换一下

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧