⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c语言强制类型转换 c-c++ - c语言 - csdn社区 community_csdn_net.htm

📁 最全的介绍C语言结构体的使用方法和使用技巧!
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0048)http://topic.csdn.net/t/20060806/20/4930851.html -->
<HTML lang=zh-CN xml:lang="zh-CN" 
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>c语言:强制类型转换 C/C++ / C语言 - CSDN社区 community.csdn.net</TITLE>
<META content=all name=robots>
<META http-equiv=Content-Language content=zh-CN>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><LINK 
href="c语言强制类型转换 C-C++ - C语言 - CSDN社区 community_csdn_net.files/topic.css" 
type=text/css rel=stylesheet>
<SCRIPT src="c语言强制类型转换 C-C++ - C语言 - CSDN社区 community_csdn_net.files/Topic.js" 
type=text/javascript></SCRIPT>

<META content=" C/C++ C语言" name=Keywords>
<META 
content=" c语言中, 能不能定义一个 void * p;          然后把p转化为 int*          后面的操作都不用再转换了,就是 int* 来使用了" 
name=description>
<META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>
<BODY>
<DIV id=wrapper>
<DIV id=innerWrapper>
<TABLE class=CSDN-PHF id=CSDNPHL cellSpacing=1 cellPadding=0 border=0>
  <TBODY>
  <TR>
    <TD><A href="http://www.csdn.net/" rel=external>CSDN首页</A></TD>
    <TD><A href="http://news.csdn.net/" rel=external>新闻</A></TD>
    <TD><A href="http://bbs.csdn.net/" rel=external><STRONG>论坛</STRONG></A></TD>
    <TD><A href="http://groups.csdn.net/" 
    rel=external><STRONG>小组</STRONG></A></TD>
    <TD><A href="http://blog.csdn.net/" 
    rel=external><STRONG>Blog</STRONG></A></TD>
    <TD><A href="http://dev.csdn.net/" rel=external>文档</A></TD>
    <TD><A href="http://download.csdn.net/" rel=external>下载</A></TD>
    <TD><A href="http://book.csdn.net/" rel=external>读书</A></TD>
    <TD><A href="http://tag.csdn.net/" 
rel=external><STRONG>Tag</STRONG></A></TD>
    <TD><A href="http://wz.csdn.net/" rel=external><STRONG>网摘</STRONG></A></TD>
    <TD><A href="http://search.csdn.net/" 
    rel=external><STRONG>搜索</STRONG></A></TD>
    <TD><A href="http://dotnet.csdn.net/" 
      rel=external><STRONG>.NET</STRONG></A></TD>
    <TD><A href="http://java.csdn.net/" 
    rel=external><STRONG>Java</STRONG></A></TD>
    <TD><A href="http://gamedev.csdn.net/" rel=external>游戏</A></TD>
    <TD><A href="http://live.csdn.net/" rel=external>视频</A></TD>
    <TD><A href="http://job.csdn.net/" rel=external>人才</A></TD>
    <TD><A href="http://prj.csdn.net/" rel=external>外包</A></TD>
    <TD><A href="http://www.dearbook.com.cn/" rel=external>第二书店</A></TD>
    <TD><A href="http://www.programmer.com.cn/" 
  rel=external>程序员</A></TD></TR></TBODY></TABLE>
<DIV id=logo><!--

<table border="0" cellspacing="0" cellpadding="0" width="770px"><tr><td style="text-align:left;"><a
href="http://community.csdn.net/" rel="external"><img class="logo" src="http://www.csdn.net/ui/images/logo_csdn.gif" alt="CSDN社区" /></a></td><td style="text-align:center"><a
href="http://g.csdn.net/5022240" rel="external"><img class="logo" src="http://topic.csdn.net/images/adv/468-60.gif" alt="" style="margin:0" /></a></td><td style="text-align:right"><a
href="http://g.csdn.net/5021657" rel="external"><img src="http://topic.csdn.net/images/adv/120_60.gif" alt="" style="margin:0"/></a></td>
</tr><tr id="bigFlash" style="text-align:center"><td colspan="3"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="760" height="300">
  <param name="movie" value="http://topic.csdn.net/images/adv/760-300.swf" />
  <param name="quality" value="high" />
  <embed src="http://topic.csdn.net/images/adv/760-300.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="300"></embed>
</object></td></tr>
</table>
<script type="text/javascript">setTimeout("document.getElementById('bigFlash').style.display='none'", 5000);</script>
--><A href="http://community.csdn.net/" rel=external><IMG class=logo alt=CSDN社区 
src="c语言强制类型转换 C-C++ - C语言 - CSDN社区 community_csdn_net.files/logo_csdn.gif"></A><A 
href="http://g.csdn.net/5022240" rel=external><IMG alt="" 
src="c语言强制类型转换 C-C++ - C语言 - CSDN社区 community_csdn_net.files/468-60.gif"></A><A 
href="http://g.csdn.net/5021657" rel=external><IMG alt="" 
src="c语言强制类型转换 C-C++ - C语言 - CSDN社区 community_csdn_net.files/120_60.gif"></A> 
<IMG style="DISPLAY: none" alt="" 
src="c语言强制类型转换 C-C++ - C语言 - CSDN社区 community_csdn_net.files/pv.aspx"> </DIV>
<DIV id=navigation>
<DIV id=search>
<DIV id=innerSearch><INPUT id=key onfocus="value=''"><A 
onclick="return Search()" 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">搜索</A>&nbsp;|&nbsp;<A 
title=功能强大的网络收藏夹,一秒钟操作就可以轻松实现保存带来的价值、分享带来的快乐 
href="javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(saveit=window.open('http://wz.csdn.net/storeit.aspx?t='+escape(d.title)+'&amp;u='+escape(d.location.href)+'&amp;c='+escape(t),'saveit','scrollbars=no,width=590,height=300,left=75,top=20,status=no,resizable=yes'));saveit.focus();">收藏</A>&nbsp;|&nbsp;<A 
onclick="return Print()" 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">打印</A>&nbsp;|&nbsp;<A 
onclick="return Close()" 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">关闭</A> </DIV></DIV>
<DIV><A class=CSDNRoom href="http://community.csdn.net/" 
rel=external>CSDN社区</A>&nbsp;&gt;&nbsp; <A 
href="http://community.csdn.net/Expert/ForumsList.asp?typenum=1&amp;roomid=56" 
rel=external>C/C++</A>&nbsp;&gt;&nbsp; <A 
href="http://community.csdn.net/Expert/ForumList.asp?typenum=1&amp;roomid=5601" 
rel=external>C语言</A> </DIV></DIV>
<DIV id=mainWrapper>
<DIV id=pageContent>
<DIV id=innerContent>
<H1>c语言:强制类型转换</H1>
<DIV class=author><A class=anchor name=Top>楼主</A>cuizhu(zhu)<INPUT class=user1 title="一级用户 该版得分小于等于100分" type=button>2006-08-06 
20:46:39 在 C/C++ / C语言 提问</DIV>
<P> <BR>&nbsp; &nbsp; c语言中, &nbsp; 能不能定义一个 &nbsp; void &nbsp; * &nbsp; p; &nbsp; 
<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
然后把p转化为 &nbsp; int* &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; 后面的操作都不用再转换了,就是 &nbsp; int* &nbsp; 来使用了 
<SPAN>问题点数:80、回复次数:15</SPAN><A 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">Top</A> </P>
<DIV class=tagad><IFRAME 
src="c语言强制类型转换 C-C++ - C语言 - CSDN社区 community_csdn_net.files/Board.htm" 
frameBorder=0 scrolling=no></IFRAME></DIV>
<H3><STRONG><A class=anchor name=r_35994271>1 楼</A>snowbirdfly(专心搞好嵌入式~~~)<INPUT class=star1 title="一星用户 该版得分小于等于10000分,大于5000分" type=button></STRONG><SPAN>回复于 
2006-08-06 20:50:49 得分 0 </SPAN></H3>
<P>那就可以直接用(int &nbsp; *)强制类型转换 &nbsp; <BR>&nbsp; 参考个例子: &nbsp; <BR>&nbsp; void 
&nbsp; foo(void* &nbsp; callbackdata) &nbsp; <BR>&nbsp; { &nbsp; <BR>&nbsp; 
cout&lt;&lt;*(int &nbsp; *)callbackdata&lt;&lt;endl; &nbsp; <BR>&nbsp; } &nbsp; 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; int &nbsp; main() &nbsp; 
<BR>&nbsp; { &nbsp; <BR>&nbsp; int &nbsp; mydata[2]={1,2}; &nbsp; <BR>&nbsp; 
foo(mydata); &nbsp; <BR>&nbsp; system("pause"); &nbsp; <BR>&nbsp; }<A 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_35994687>2 楼</A>dx30611(想要clean code)<INPUT class=user4 title="四级用户 该版得分小于等于2000分,大于1000分" type=button></STRONG><SPAN>回复于 
2006-08-06 21:34:51 得分 0 </SPAN></H3>
<P>当然可以 &nbsp; <BR>&nbsp; c语言有个函数原型为void &nbsp; *memcpy( &nbsp; void &nbsp; *to, 
&nbsp; const &nbsp; void &nbsp; *from, &nbsp; size_t &nbsp; count &nbsp; ); 
&nbsp; <BR>&nbsp; 把实参传递给形参时可以使用任意类型的指针<A 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_35994715>3 楼</A>cuizhu(zhu)<INPUT class=user1 title="一级用户 该版得分小于等于100分" type=button></STRONG><SPAN>回复于 
2006-08-06 21:37:08 得分 0 </SPAN></H3>
<P>我说的是这个意思 &nbsp; 先声明个void &nbsp; *p &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; 后面有很多代码都要用到p &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; 我想根据不同的情况,把p转换为其他的类型 &nbsp; <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; 有没有好点的办法达到这种效果<A 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_35994798>4 
楼</A>sankt(宠辱不惊,看庭前花开花落;去留无意,望天空云卷云舒.)<INPUT class=star1 title="一星用户 该版得分小于等于10000分,大于5000分" type=button></STRONG><SPAN>回复于 
2006-08-06 21:45:13 得分 0 </SPAN></H3>
<P>当然可以的 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; void &nbsp; * &nbsp; 可以强制转化任何其他的指针 
&nbsp; <BR>&nbsp; void &nbsp; *p; &nbsp; <BR>&nbsp; int &nbsp; *q &nbsp; = 
&nbsp; (int &nbsp; *)p; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; <A 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_35994823>5 楼</A>lj860603(跑吧,键键)<INPUT class=user5 title="五级用户 该版得分小于等于5000分,大于2000分" type=button></STRONG><SPAN>回复于 
2006-08-06 21:47:31 得分 0 </SPAN></H3>
<P>我明白楼主的意思。 &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; 那样是不可以的。可以强制转换,但以后要用还是要强制转换!<A 
href="http://topic.csdn.net/t/20060806/20/4930851.html#">Top</A></P>
<H3><STRONG><A class=anchor name=r_35994828>6 
楼</A>sankt(宠辱不惊,看庭前花开花落;去留无意,望天空云卷云舒.)<INPUT class=star1 title="一星用户 该版得分小于等于10000分,大于5000分" type=button></STRONG><SPAN>回复于 
2006-08-06 21:48:21 得分 0 </SPAN></H3>
<P>void的字面意思是“无类型”,void &nbsp; *则为“无类型指针”,void &nbsp; *可以指向任何类型的数据。 &nbsp; 
<BR>&nbsp; &nbsp; <BR>&nbsp;   void几乎只有“注释”和限制程序的作用,因为从来没有人会定义一个void变量,让我们试着来定义: 
&nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; &nbsp; <BR>&nbsp; void &nbsp; a; &nbsp; 
<BR>&nbsp; &nbsp; <BR>&nbsp;   这行语句编译时会出错,提示“illegal &nbsp; use &nbsp; of &nbsp; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -