c程序语言设计内容摘要:

return 1。 else return n * factorial(n 1)。 } Functions  function prototyping  int translate(float x, float y, flaoat z)。  empty argument list  func()、 func(void)  uncertain argument list  creating your own libraries Introduction to pointers  the ‗amp。 ‘ operator precede the identifier name with ‗amp。 ‘ and it will produce the address of that identifier. see ―‖  pointer definition For a type T , T * is the type “ pointer to T”, that is , a variable of type T * can hold the address of an object of type T. Introduction to pointers  The operator that defines a pointer ‗*‘  Insert a star ‗*‘ between the type and the identifier int* ip。 // ip points to an int value int a = 47。 int* ipa = amp。 a。 *ipa = 100。 Introduction to pointers  the most basic use of pointers To change ―outside objects‖ from within a function.  Ordinarily, when you pass an argument to a function, a copy of that argument is made inside the function. This is referred to as passbyvalue.  see ―‖ Introduction to pointers  want to modify the outside object pass a pointer into a function instead of an ordinary value, we are actually passing an alias to the outside object, enabling the function to modify that outside object. This is referred to as passbyaddress. see ―‖ Introduction to C++ references Pointers work roughly the same in C and in C++, but C++ adds an additional way to pass an address into a function. This is passbyreference . see ―‖ Introduction to C++ references  A reference is an alternative name for an object.  we must initialize the reference while define it. int i = 1。 intamp。 r1 = i。 // ok, r1 initialized intamp。 r2。 // error, miss initializer extern intamp。 r3。 // ok, r3 initialized elsewhere Pointer to void  void * : pointer to any type of object. int main() { void* vp。 char c。 int i。 float f。 double d。 vp = amp。 c。 vp = amp。 i。 vp = amp。 f。 vp = amp。 d。 } ///:~ Pointer to void  before you can use the pointer void *, you must cast it to the correct type int main() { int i = 99。 void* vp = amp。 i。 // Can39。 t dereference a void pointer: // *vp = 3。 // Compileti。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。