鱼C论坛

 找回密码
 立即注册
查看: 2540|回复: 5

一道题怎么做啊,c语言的

[复制链接]
发表于 2014-7-26 08:42:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 淡然916 于 2014-8-13 10:06 编辑

#include<stdio.h>

int square(int n){
        return n*n;
}
int main(){
        int num = 2;
        printf ("The original number is %d\n" , num);
        
        printf ("The new value of number is %d\n" , num);
        return 0;
}


请将square函数的返回信改为void

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-7-26 08:49:29 | 显示全部楼层
本帖最后由 oggplay 于 2014-7-26 09:04 编辑

[b]

  1. #include <stdio.h>

  2. void square(int *n) {
  3.         *n=(*n)*(*n);
  4. }


  5. int main( ){
  6.         int num = 2;
  7.         printf ("The original number is %d\n" , num);
  8.         square( &num);
  9.         printf ("The new value of number is %d\n" , num);
  10.         return 0;
  11. }
复制代码




[/b]
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-7-26 08:55:22 | 显示全部楼层
谢谢,我以为用typedef
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-7-26 08:58:57 | 显示全部楼层
用指针
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-7-26 10:59:49 | 显示全部楼层
本帖最后由 戏++ 于 2014-7-26 11:02 编辑

c++可以用引用吧,c好像也行啊,试试
  1. #include <stdio.h>

  2. void square(int &n)
  3. {
  4.         n=n*n;
  5. }


  6. int main( ){
  7.         int num = 2;
  8.         printf ("The original number is %d\n" , num);
  9.         square( num);
  10.         printf ("The new value of number is %d\n" , num);
  11.         return 0;
  12. }
复制代码



小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-7-26 11:14:37 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-10 15:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表