热门搜索 :
考研考公
您的当前位置:首页正文

指针与数组练习题3

来源:东饰资讯网
Paste_Image.png
#include <stdio.h>

typedef int BOOL;
#define FALSE 0;
#define TRUE 1;


BOOL search(int a[], int n, int key);

void main(){
    BOOL judge;
    int a[4] = {0,1,2,3};
    judge = search(a, 4, 5);
    if(judge) //这里如果用if(judge == TRUE)就会报错,为什么?
        printf("Find the key.\n");
    else 
        printf("Cannot find the key.\n");
}

BOOL search(int a[], int n, int key){
    int *p = a; 
    BOOL judge;
    for(; p < (a + n); p++){
        if(*p == key){
            judge = TRUE;
        }
        else
            judge = FALSE;
    }
    return judge;
}
Top