UNIX 下C編程 代碼02

int max(int a[], int n)
{
	int m = a[0];
	for(int i=1; i<n; i++)
		if(m<a[i])
			m = a[i];
	return m;
}
double v=1234.5;

==========================
#ifndef _MAX_
#define _MAX_

int max(int a[], int n);
extern double v;//變量聲明

#endif

==========================
#include <stdio.h>
int main()
{
	printf("hello world!\n");
	return 0;
}


==========================
#include <stdio.h>

int main()
{//_cplusplus
	puts(__DATE__);
	puts(__TIME__);
	puts(__FILE__);
	puts(__func__);
	printf("%d\n", __LINE__);
	return 0;
}


==========================
#include <stdio.h>
#pragma pack(1)
typedef struct Person{
	char name[17];
	int age;
	char gender;
} Person;
int main()
{
	printf("%d\n", sizeof(Person));
	return 0;
}

==========================
#include <stdio.h>
#include "dll.h"
#include <dlfcn.h>

int main()
{
	void* handle = dlopen("./libmax.so",RTLD_NOW);
	if(handle==NULL){
		puts(dlerror());
		return 1;
	}
	double* pv = dlsym(handle, "v");
	int(*pf)(int[],int) = dlsym(handle, "max");
	printf("%lg\n", *pv);
	int x[]={3,9,2,6,8,5};
	printf("%d\n", pf(x,6));
	dlclose(handle);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章