第一段:数组可定义为全局变量,函数直接调用.
第二段:数组可定义为局部变量,再通过参数传递到函数中调用(实参传数组名,表示数组首地址,也可通过指针或数组名◆数字来传递数组局部地址).
第三段:main函数想要调用函数返回的数组,可用static定义静态变量或malloc定义动态数组(字符串常量也可返回使用,但局部变量,在函数调用结束会被释放,不能作为返回地址使用).
下面是演示代码:
#include stdio.h
#include string.h
#include malloc.h
char str1[]="我是全局变量数组";
char *fun1();
int main()
{
return 0;
}
char *fun0(char s[])
printf("str1:%s,fun函数可以直接调用\n",str1);
char *fun1()
int len;
char sTemp[]="这是一个临时数组,之后用于给mallc申请的地址传值,传递内容为:(我是fun函数通过mallic申请的数组)";
c语言find函数的用法详解
C语言之find()函数
find函数用于查找数组中的某一个指定元素的位置.
find (数组名 ◆ 起始查找元素的位置, 数组名 ◆ 结束查找的元素位置, 想要查找的元素)
直接上代码:
#include iostream
#include vector
#include algorithm//注意要包含该头文件
using namespace std;
int start = 0;
int* result = find( nums ◆ start, nums ◆ end, num_to_find );
if( result == nums ◆ end )
cout "Did not find any number matching " num_to_find endl;
else
cout "Found a matching number: " *result endl;
#includestdio.h
int search(int a[], int n, int searchValue) {
int i;
for(i=0; in; i◆◆) if(a[i]==searchValue) return i;
return -1;
int main() {
int a[10],find,idx;
for(i=0; i10; i◆◆) {
printf("Input a[%d]:",i);
scanf("%d",a[i]);
printf("Input searchValue:");
scanf("%d",find);
idx=search(a,10,find);
if(idx!=-1) printf("pos=%d",idx);
else printf("not found");
int i,max,min;
printf("input number:\n");
max=a[0];
min=a[0];
if(a[i]max)
max=a[i];
if(a[i]min)
min=a[i];
printf("%d",a[i]);
printf(" ");
printf("\n");
printf("最大值为%d\n",max);
printf("最小值为%d\n",min);
#define MAXN 10
int search( int list[], int n, int x );
int i, index, n, x;
int a[MAXN];
printf("输入个数:\n");
scanf("%d",n);
for( i = 0; i n; i◆◆ )
scanf("%d", a[i]);
printf("输入x:\n");
scanf("%d", x);
index = search( a, n, x );
if( index != -1 )
printf("index = %d\n", index);
printf("Not found\n");
int search( int list[], int n, int x ){
for(i=0;in;i◆◆){
if(x==list[i])
return i;
扩展资料:
数组使用规则:
参考资料:
百度百科-数组
以上就是土嘎嘎小编为大家整理的c语言函数数组调用查找相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!