#import <Foundation/Foundation.h>
struct MyStruct
{
int id;
char* name;
} *pMyStruct;
typedef int(*fun)(int, int);
int add(int m, int n)
{
return m + n;
}
int mul(int m, int n)
{
return m * n;
}
// 指针
int main(int argc, const char * argv[]) {
@autoreleasepool {
int count = 10;
int *pCount = &count;
printf("pCount = %d\n", pCount);//count变量的地址
printf("*pCount = %d\n", *pCount);//获得countn变量的值
struct MyStruct myStruct;//定义结构体变量
myStruct.id = 123;//给结构体进行赋值
myStruct.name = "xyz";
pMyStruct = &myStruct;//取结构体的地址
printf("%s",pMyStruct->name);//取结构体name中的值
fun f = mul;//add; 函数指针指向mul函数
printf("\n%d\n", f(4,6));//指向mul函数并进行打印
int intValues[] = {1,2,3,4,5};//定义数组
int *pValue;//定义数组指针
pValue = intValues;//pValue指向intValues第一个地址
printf("\npValue = %d\n", *pValue);//输出数组intValues第一个值
printf("\nintValues[2] = %d\n", *(pValue + 2));//输出intValues的第三个值
}
return 0;
}