首页 > 电脑

c语言修正一下语法

更新时间2019-11-02 09:49:51

#include <stdio.h>

#include <windows.h>

//#include "Test.h"

 

struct test

{

 

 int a;

 int b;

 

int test1( int a,int b )

{

 

   return a + b;

 

}

 

};

 

int main()

{

  test s;

  s.test1(3,4);

 

printf("%d ",s.test1);

 

return 0;

 

}

想输出a+b的值。应该怎么改??

首先,你的程序不是c语言的,是C++的(C和C++是二种不同的语言),C不支持类的

其次,你对函数不是很理解 ,函数返回值不能记忆的

两个方法

1。直接用

test s;
   printf("%d ",s.test1(3,4)); //输出

2。用临时变量

      test s;
   int t=s.test1(3,4); //得到结果
   printf("%d ",t); //输出结果

相关标签:c语言

上一篇:杜比音效和DTS音效哪个音质更好?

下一篇:编写一个程序,提示用户以(xxx)xxx-xxxx的格式输入电话号码