📄 index.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN"><!-- This collection of hypertext pages is Copyright 1995-2005 by Steve Summit. --><!-- Content from the book "C Programming FAQs: Frequently Asked Questions" --><!-- (Addison-Wesley, 1995, ISBN 0-201-84519-9) is made available here by --><!-- permission of the author and the publisher as a service to the community. --><!-- It is intended to complement the use of the published text --><!-- and is protected by international copyright laws. --><!-- The on-line content may be accessed freely for personal use --><!-- but may not be published or retransmitted without explicit permission. --><!-- --><!-- this page built Sat Dec 24 21:47:45 2005 by faqproc version 2.7 --><!-- from source file pointers.sgml dated Wed Dec 21 13:07:10 2005 --><!-- corresponding to FAQ list version 4.0 --><html><!-- Mirrored from c-faq.com/ptrs/index.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:54:22 GMT --><head><meta name=GENERATOR content="faqproc"><title>Pointers</title></head><body bgcolor="#ffffff"> <a href="../index-2.html"><img src="../images/buttontop.gif" alt="top/contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><hr><H1>4. Pointers</H1><p><a href="goodfor.html" rel=subdocument>4.1</a>What are pointers really good for, anyway?</p><p><a href="mimic.html" rel=subdocument>4.2</a>I'm trying to declare a pointer and allocate some space for it,but it'snot working.What's wrong withthis code?<pre>char *p;*p = malloc(10);</pre></p><p><a href="unopprec2.html" rel=subdocument>4.3</a>Does <TT>*p++</TT> increment <TT>p</TT>,or what it points to?</p><p><a href="explscale.html" rel=subdocument>4.4</a>I'mtrying to usepointers tomanipulate an array of <TT>int</TT>s.What's wrong with this code?<pre> int array[5], i, *ip; for(i = 0; i < 5; i++) array[i] = i; ip = array; printf("%d\n", *(ip + 3 * sizeof(int)));</pre>I expected the last line to print 3,but it printed garbage.</p><p><a href="castincr.html" rel=subdocument>4.5</a>Ihavea <TT>char *</TT> pointerthat happens to point tosome <TT>int</TT>s,and I want to step it over them.Why doesn't<pre>((int *)p)++;</pre>work?</p><p><a href="voidparith.html" rel=subdocument>4.6</a>Why can't I perform arithmetic on a <TT>void *</TT> pointer?</p><p><a href="align.html" rel=subdocument>4.7</a>I've got some code that's trying to unpack external structures, but it's crashingwith a message about an ``unaligned access.''What does this mean?</p><p><a href="passptrinit.html" rel=subdocument>4.8</a>I have a function which accepts,and is supposed to initialize,a pointer:<pre> void f(int *ip) { static int dummy = 5; ip = &dummy; }</pre>But when I call it like this:<pre> int *ip; f(ip);</pre>thepointer in the caller remains unchanged.</p><p><a href="genericpp.html" rel=subdocument>4.9</a>Suppose I want to write a function that takes a generic pointeras an argument and I want to simulate passing it by reference.Can I give the formal parameter type <TT>void **</TT>,and do something like this?<pre> void f(void **); double *dp; f((void **)&dp);</pre></p><p><a href="refconst.html" rel=subdocument>4.10</a>I have a function<pre> extern int f(int *);</pre>which accepts a pointer to an <TT>int</TT>.How can I pass a constantby reference?A call like<pre> f(&5);</pre>doesn't seem to work.</p><p><a href="passbyref.html" rel=subdocument>4.11</a>Does C even have ``pass by reference''?</p><p><a href="funccall.html" rel=subdocument>4.12</a>I've seen different syntax used for calling functions via pointers.What's the story?</p><p><a href="generic.html" rel=subdocument>4.13</a>What's the total generic pointer type?My compiler complainedwhen I tried to stuff function pointers into a <TT>void *</TT>.</p><p><a href="int2ptr.html" rel=subdocument>4.14</a>How are integers converted to and from pointers?Can I temporarily stuff an integer into a pointer,or vice versa?</p><p><a href="int2charp.html" rel=subdocument>4.15</a>How do I convert an <TT>int</TT> to a <TT>char *</TT>?I tried a cast, but it's not working.</p><p><a href="charstarws3.html" rel=subdocument>4.16</a>What's wrong withthisdeclaration?<pre>char* p1, p2;</pre>I get errors when I try touse<TT>p2</TT>.</p><p><a href="nearfar2.html" rel=subdocument>4.17</a>What are ``near'' and ``far'' pointers?</p><hr><p><a href="../index-2.html">top</a></p><p><a href="../questions.html"><img src="../images/buttontop.gif" alt="contents"></a><a href="../search.html"><img src="../images/buttonsrch.gif" alt="search"></a><br><a href="../about.html">about this FAQ list</a> <a href="../eskimo.html">about eskimo</a> <a href="../search.html">search</a> <a href="../feedback.html">feedback</a> <a href="copyright.html">copyright</a><p>Hosted by<a href="http://www.eskimo.com/"><img src="../../www.eskimo.com/img/link/eskitiny.gif" alt="Eskimo North"></a></p></body><!-- Mirrored from c-faq.com/ptrs/index.html by HTTrack Website Copier/3.x [XR&CO'2008], Sat, 14 Mar 2009 07:54:28 GMT --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -