论坛元老
 
- 积分
- 6679
- 金钱
- 6679
- 注册时间
- 2015-8-25
- 在线时间
- 1036 小时
|
发表于 2020-2-28 08:41:03
|
显示全部楼层
给你个C语言的测试例程:
#include <stdio.h>
typedef unsigned short u16;
struct stu
{
u16 a;
u16 b;
u16 c;
};
struct stu aa;
u16 cc;
void test(u16 s)
{
int a = 5;
int b = 6;
s = a + b;
cc = a + b;
printf("the \"s\" is %d,the \"cc\" is %d,the \"aa.a\" is %d\r\n",s,cc,aa.a);
}
int main()
{
/* 我的第一个 C 程序 */
printf("Hello, World! \n");
test(aa.a);
printf("The \"aa.a\" is %d\r\n",aa.a);
return 0;
}
输出结果:
Hello, World!
the "s" is 11,the "cc" is 11,the "aa.a" is 0
The "aa.a" is 0
第二个例程:
#include <stdio.h>
typedef unsigned short u16;
struct stu
{
u16 a;
u16 b;
u16 c;
};
struct stu aa;
u16 cc;
void test(u16 *s)
{
int a = 5;
int b = 6;
*s = a + b;
cc = a + b;
printf("the \"*s\" is %d,the \"cc\" is %d,the \"aa.a\" is %d\r\n",*s,cc,aa.a);
}
int main()
{
/* 我的第一个 C 程序 */
printf("Hello, World! \n");
test(&aa.a);
printf("The \"aa.a\" is %d\r\n",aa.a);
return 0;
}
输出结果:
Hello, World!
the "*s" is 11,the "cc" is 11,the "aa.a" is 11
The "aa.a" is 11
你自己分析下吧,对你的“最终我的理解是 作为参数使用的时候在函数内部是不能进行赋值操作的。至少结构体的形式是不可以”这个来说,C是不存在这样子的情况的,只是你没用对方法 |
|