我如何调用增量以增加计数? [英] How Would I Call Increments To Increase The Count?

查看:88
本文介绍了我如何调用增量以增加计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本:



  int 增量( int  x)
{
return x + 1 ;
}

void increment2( int * x)
{
* x = * x + 1 ;
}

int main( void
{
int count = 0 ;
// 呼叫增量...
// 调用increment2 ...

解决方案

< blockquote> Increment 将一个int作为参数并返回一个int,因此 count 将进入,并被分配给无论出来什么



Increment2 略有不同,它直接递增地址的int 它被传递(它应该检查一个NULL指针),所以你必须在 count 的地址/>
如果没有实际为你完成作业,我的解释不会简单:)


My Script:

int increment(int x)
{
  return x + 1;
}

void increment2(int *x)
{
  *x = *x + 1; 
}

int main(void)
{
  int count = 0;
  // call increment...
  // call increment2...

解决方案

Increment takes an int as a param and returns an int, so count would go in, and be assigned to whatever came out

Increment2 is slightly different, it directly increments the int at the address it was passed (it should check for a NULL pointer), so you'd have to pass the address of count in

I can't make the explanation simpler than that without actually doing your homework for you :)


这篇关于我如何调用增量以增加计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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