下面程序的最后几行:
“Array_Fountion.show(Array_Fountion.name,Array_Fountion.length);
Array_Fountion.insertion_sort();
Array_Fountion.show();”,能编译通过并运行成功,想知道为什么。。。如果没有传入参数Array_Fountion.name,Array_Fountion.length,显然会报错,混乱中。。。。。
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int *name;
int length;
void (*show)();
void (*insertion_sort)();
}array;
void show_array(int *A,int A_Length)
{
int i=0;
for(i=0;i<A_Length;i++)
{
printf("%d ",A[i]);
}
printf("\n");
}
void Insertion_Sort(int A[],int n)
{
int j=0,i=0;
int key=0;
for(j=1;j<n;j++)
{
key=A[j];
i=j-1;
while(i>=0&&key<A[i])
{
A[i+1]=A[i];
i--;
}
A[i+1]=key;
}
printf("Insertion_Sort Done!\n");
}
void Initial_Array(array *string,int *Array_Int,int Array_Length)
{
string->name=Array_Int;
string->length=Array_Length;//等价于(*string).length=11;
string->show=show_array;//等价于show=&show_array
string->insertion_sort=Insertion_Sort;
}
int main()
{
int A[]={8,7,6,5,4,3,2,123,45,666};
array Array_Fountion;
Initial_Array(&Array_Fountion,A,sizeof(A)/sizeof(*A));
Array_Fountion.show(Array_Fountion.name,Array_Fountion.length);
Array_Fountion.insertion_sort();
Array_Fountion.show();
return 0;
}
共7条
1/1 1 跳转至页

编译的错误信息如下:
--------------------配置: test02 - Debug--------------------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
..\test02.cpp:
Warning W8004 ..\test02.cpp 16: 'i' is assigned a value that is never used in function show_array(int *,int)
Warning W8004 ..\test02.cpp 27: 'key' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'i' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'j' is assigned a value that is never used in function Insertion_Sort(int *,int)
Error E2034 ..\test02.cpp 46: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2034 ..\test02.cpp 47: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2226 ..\test02.cpp 56: Extra parameter in call in function main()
*** 3 errors in Compile ***
test02.obj - 3 个错误, 4 个警告
--------------------配置: test02 - Debug--------------------
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
..\test02.cpp:
Warning W8004 ..\test02.cpp 16: 'i' is assigned a value that is never used in function show_array(int *,int)
Warning W8004 ..\test02.cpp 27: 'key' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'i' is assigned a value that is never used in function Insertion_Sort(int *,int)
Warning W8004 ..\test02.cpp 26: 'j' is assigned a value that is never used in function Insertion_Sort(int *,int)
Error E2034 ..\test02.cpp 46: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2034 ..\test02.cpp 47: Cannot convert 'void (*)(int *,int)' to 'void (*)()' in function Initial_Array(array *,int *,int)
Error E2226 ..\test02.cpp 56: Extra parameter in call in function main()
*** 3 errors in Compile ***
test02.obj - 3 个错误, 4 个警告
共7条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
“我踩过的那些坑”主题活动——第001期 | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【我踩过的那些坑】STM32cubeMX软件的使用过程中的“坑”被打赏50分 | |
新手必看!C语言精华知识:表驱动法被打赏50分 | |
【我踩过的那些坑】STM32的硬件通讯调试过程的“坑”被打赏50分 | |
【我踩过的那些坑】晶振使用的问题被打赏100分 | |
【我踩过的那些坑】电感选型错误导致的处理器连接不上被打赏50分 | |
【我踩过的那些坑】工作那些年踩过的记忆深刻的坑被打赏10分 | |
【我踩过的那些坑】DRC使用位置错误导致的问题被打赏100分 | |
我踩过的那些坑之混合OTL功放与落地音箱被打赏50分 | |
汽车电子中巡航控制系统的使用被打赏10分 | |
【我踩过的那些坑】工作那些年踩过的记忆深刻的坑被打赏100分 |