一道题怎么做啊,c语言的
本帖最后由 淡然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
本帖最后由 oggplay 于 2014-7-26 09:04 编辑
#include <stdio.h>
void square(int *n) {
*n=(*n)*(*n);
}
int main( ){
int num = 2;
printf ("The original number is %d\n" , num);
square( &num);
printf ("The new value of number is %d\n" , num);
return 0;
}
谢谢,我以为用typedef 用指针 本帖最后由 戏++ 于 2014-7-26 11:02 编辑
c++可以用引用吧,c好像也行啊,试试
#include <stdio.h>
void square(int &n)
{
n=n*n;
}
int main( ){
int num = 2;
printf ("The original number is %d\n" , num);
square( num);
printf ("The new value of number is %d\n" , num);
return 0;
}
oggplay 发表于 2014-7-26 08:49
太棒了!!
页:
[1]