Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

c°æµÄ»Øµ÷º¯ÊýÓëc++°æµÄÐ麯Êý

CÓïÑԵĻص÷º¯Êý˼Ïë´úÂ룺
#include <stdio.h>
void *max(void *base, unsigned int nmemb, unsigned int size,
    int (*compar)(const void *, const void *))
{
    int i;
    void* max_data = base;
    char* tmp = base;
    for (i=1; i<nmemb; i++) {
        tmp = tmp + size;
        if (compar(max_data, tmp) < 0) {
            max_data = tmp;
        }
    }
    return max_data;
}
int compar_int(const void* x, const void* y)
{
    return (*(int*)x - *(int*)y);
}
typedef struct _Student {
    char name[16];
    int score;
} Student;
int compar_student(const void* x, const void* y)
{
    return (((Student*)x)->score - ((Student*)y)->score);
}
int main()
{
    int data_int[] = {3, 2, 56, 41, 22, 7};
    unsigned int count_int = sizeof(data_int) / sizeof(int);
    int* max_int = (int*)max(data_int, count_int, sizeof(int), &compar_int);
    printf("max int: %d\n", *max_int);
    Student data_student[] = {
        {"Kate", 92},
        {"Green", 85},
        {"Jet", 77},
        {"Larry",88},
    };
    unsigned int count_student = sizeof(data_student) / sizeof(Student);
    Student* high_score = (Student*)max(data_student,
        count_student, sizeof(Student), &compar_student);
    printf("high score -- name:%s, score:%d\n", high_score->name, high_score->score);
  


Ïà¹ØÎĵµ£º

CºÍC++³ÌÐòԱѧϰÀú³Ì

ºÜÓвο¼ÒâÒåµÄѧÀúÁ÷³Ì¡£
¡¡¡¡1¡¢¿ÉÒÔ¿¼ÂÇÏÈѧϰC.

¡¡¡¡´ó¶àÊýʱºò£¬ÎÒÃÇѧϰÓïÑÔµÄÄ¿µÄ£¬²»ÊÇΪÁ˳ÉΪһ¸öÓïÑÔר¼Ò£¬¶øÊÇÏ£Íû³ÉΪһ¸ö½â¾öÎÊÌâµÄר¼Ò¡£×öÒ»¸öÓÐÓõijÌÐòÔ±£¬×öÒ»¸ö׬ǮµÄ³ÌÐòÔ±¡£ÎÒÃǵļÛÖµ£¬½«ÌåÏÖÔÚ¿Í»§¼ÛÖµÉÏ£¬¶ø²»ÊÇÓïÑÔдµÃºÃ²»ºÃ¿´¡£


¡¡¡¡C++ÊÇCµÄÒ»¸öÃæÏò¶ÔÏóµÄ½âÊÍ£¬C++ΪCÀ ......

C/C++ÖÐÖ¸ÕëºÍÒýÓÃÖ®Ïà¹ØÎÊÌâÑо¿

Ò»¡¢»ù±¾ÖªÊ¶
Ö¸ÕëºÍÒýÓõÄÉùÃ÷·½Ê½£º
ÉùÃ÷Ö¸Õ룺 char* pc;
ÉùÃ÷ÒýÓ㺠char c = 'A'
                  char& rc = c;
ËüÃǵÄÇø±ð£º
¢Ù´ÓÏÖÏóÉÏ¿´£¬Ö¸ÕëÔÚÔËÐÐʱ¿ÉÒԸıäÆäËùÖ¸ÏòµÄÖµ£¬¶øÒýÓÃÒ»µ©ºÍij¸ö¶ÔÏó°ó¶¨ºó ......

50¸öc/c++Ô´´úÂëÍøÕ¾

C/C++ÊÇ×îÖ÷ÒªµÄ±à³ÌÓïÑÔ¡£ÕâÀïÁгöÁË50ÃûÓÅÐãÍøÕ¾ºÍÍøÒ³Çåµ¥£¬ÕâЩÍøÕ¾Ìṩc/c++Ô´´úÂë ¡£Õâ·ÝÇåµ¥ÌṩÁËÔ´´úÂëµÄÁ´½ÓÒÔ¼°ËüÃǵÄС˵Ã÷¡£ÎÒÒѾ¡Á¦°üÀ¨×î¼ÑµÄC/C++Ô´´úÂëµÄÍøÕ¾¡£Õâ²»ÊÇÒ»¸öÍêÕûµÄÇåµ¥£¬ÄúÓн¨Òé¿ÉÒÔÁªÏµÎÒ£¬ÎÒ½«»¶Ó­ÄúµÄ½¨ Ò飬ÒÔ½øÒ»²½¼ÓÇ¿Õâ·½ÃæµÄÇåµ¥¡£ 
1¡¢http://snippets.dzone.com/tag/c/&nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ