在malloc的类型转换是否需要? [英] Is typecast required in malloc?

查看:116
本文介绍了在malloc的类型转换是否需要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是malloc的使用类型转换?如果我不写在malloc的类型转换,然后会是什么回报? (为什么在malloc的类型转换需要?)

What is the use of typecast in malloc? If I don't write the typecast in malloc then what will it return? (Why is typecasting required in malloc?)

推荐答案

我假定你的意思是这样的:

I assume you mean something like this:

为int * IPTR =(INT *)的malloc(/ * *的东西/);

而在C,你不必(也不应该)从的malloc 把返回指针。这是一个无效* 和C,它是隐式转换为另一个指针类型。

And in C, you do not have to (and should not) cast the return pointer from malloc. It's a void * and in C, it is implicitly converted to another pointer type.

为int * IPTR =的malloc(/ * *的东西/);

是preferred形式。

Is the preferred form.

这并不适用于C ++,它不共享相同的无效* 隐式转换行为。

This does not apply to C++, which does not share the same void * implicit cast behavior.

这篇关于在malloc的类型转换是否需要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆