博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How does “void *” differ in C and C++?
阅读量:7153 次
发布时间:2019-06-29

本文共 646 字,大约阅读时间需要 2 分钟。

http://www.geeksforgeeks.org/g-fact-12-2/

C allows a void* pointer to be assigned to any pointer type without a cast, whereas C++ does not; this appears often in C code using malloc memory allocation. For example, the following is valid in C but not C++:

 1 void* ptr; 2 int *i = ptr; /* Implicit conversion from void* to int* */ 

or similarly:

 1 int *j = malloc(sizeof(int) * 5); /* Implicit conversion from void* to int* */ 

In order to make the code compile in both C and C++, one must use an explicit cast:

1 void* ptr;2 int *i = (int *) ptr;3 int *j = (int *) malloc(sizeof(int) * 5);

Source:

转载于:https://www.cnblogs.com/lyleslie/p/4829374.html

你可能感兴趣的文章
AutoMapper使用手册(一)
查看>>
基本类型赋值转换规则表
查看>>
hackerrank-knapsack
查看>>
SessionFactory的创建和Session的获得
查看>>
Hybrid框架UI重构之路:四、分而治之
查看>>
iOS项目的目录结构(Cocoa China)
查看>>
取消word中所有超链接
查看>>
javascript:addEventListener
查看>>
Mysql函数INSTR、LOCATE、POSITION VS LIKE
查看>>
atoi()函数的实现
查看>>
基于.net开发chrome核心浏览器【三】
查看>>
多种方法实现Loading(加载)动画效果
查看>>
AABB边框、OBB边框、通过比较球包围
查看>>
Atitit. 软件开发中的管理哲学--一个伟大的事业必然是过程导向为主 过程导向 vs 结果导向...
查看>>
基于opencv的小波变换
查看>>
JS产生随机数的几个用法!
查看>>
Android开发UI之ViewPager及PagerAdapter
查看>>
浏览器默认样式(User Agent Stylesheet)
查看>>
C语言宏定义技巧
查看>>
所有Mac用户都需要知道的9个实用终端命令行
查看>>