Node * a 与Node* &a



struct Node{

  int a[10];

  int length;

}


int  main(){

  Node* a;

 initNode(a);

  return 0;

}


错误方法:

  void initNode(Node *a){

     a = (Node*)malloc(sizeof(Node));

      a->lenght=0;

}

它不会改变main函数中的a原因是main中传入的是地址给initNode方法中的a而a第一句是重新申请个地址,所以它的地址不是原来的。它已经脱离了main中a它的改变对main中那个变量没有一点影响

正确的方法:

void initNode(Node* &a){

  a = (Node*)malloc(sizeof(Node));

   a->lenght=0;

}

它的含义就是把main中那个指针变量等价与initNode中的这个指针变量。它们为同一个指针。为什么了,我想是它传入的是存储指针的地址而不是指针指向地址。为了理解就认为它就把自己传入。

另外有个误区对与数组int a[10];我们不能这样

void initArray(int a[]){

a = {1,2,3,4,5,6,7};

}

a在是数组的首地址,它是个常量你这要做的意思是把a的地址又改变了,常量怎么可以改变了。。。。就如1不能为2

解决方法我们可以用指针变量


转载自:http://blog.csdn.net/yinbucheng/article/details/51590442

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The first edition of Node.js in Action was about web development with a particular focus on the Connect and Express web frameworks. Node.js in Action, Second Edition has been updated to suit the changing requirements of Node development. You’ll learn about front-end build systems, popular Node web frameworks, and how to build a web application with Express from scratch. You’ll also learn how to create automated tests and deploy Node web applications. Node is being increasingly used for command-line developer tools and desktop applications with Electron, so you’ll find chapters dedicated to both of these areas. This book assumes you’re familiar with basic programming concepts. The first chapter provides an overview of JavaScript and ES2015 for those of you who haven’t yet discovered the joys of modern JavaScript. Roadmap This book is organized into three parts. Part 1 provides an introduction to Node.js, teaching the fundamental techniques needed to develop with it. Chapter 1 explains the characteristics of JavaScript and Node and steps through example code. Chapter 2 guides you through fundamental Node.js programming concepts. Chapter 3 is a full tutorial on how to build a web application from scratch. Part 2, the largest section of the book, focuses on web application development. Chapter 4 dispels some of the mystery around front-end build systems: if you’ve ever had to use webpack or Gulp in a project but didn’t really understand it, this is the chapter for you. Chapter 5 reviews some of the most popular server-side frameworks available for Node, and chapter 6 goes into Connect and Express in more depth. Chapter 7 is dedicated to templating languages, which can improve your productivity when writing server-side code. Most web applications need a database, so chapter 8 covers the many types of databases that you can use with Node, from relational to NoSQL. Chapters 9 and 10 deal with testing and deployment, and this includes cloud deployment. Part 3 goes be

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值