#include <stdio.h>
void changValue1(int x,int y);
void changValue1(int x,int y)
{
int tmp = 0;
tmp = x;
x = y;
y = tmp;
}
void changValue2(int *x,int *y);
void changValue2(int *x,int *y)
{
int tmp = 0;
tmp = *x;
*x = *y;
*y = tmp;
}
// 多返回值的函数
int calc(int a,int b,int *c);
int calc(int a,int b,int *c)
{
int d = a + b;
*c = a - b;
return d;
}
int main(int argc, const char * argv[])
{
// 指针的概念
/*
int i = 10,j = 11;
int *p;
p = &i;
printf("i的地址:%p",p);
// 通过指针把i的内容取出来
printf("i的内容:%d",*p);
printf("\n");
*p = 12;
printf("i的内容:%d",*p);
// insert code here...
//printf("Hello, World!\n");
*/
// 指针的使用
int a = 10,b = 20;
changValue1(a, b);
printf("a = %d b = %d",a,b);
printf("\n");
//changValue2(&a, &b);
printf("a = %d b = %d",a,b);
printf("\n");
int c = 0;
int e = calc(a, b, &c);
printf("e = %d c = %d",e,c);
int arr[] = {2,5,4,1};
int len = sizeof(arr) / sizeof(arr[0]);
int *p;
for (int i = 0; i< len - 1; i++)
{
p = arr;
for (int j = 0; j < len - 1 - i; j++)
{
if (*p > *(p+1))
{
int tmp = 0;
tmp = *p;
*p = *(p+1);
*(p+1) = tmp;
}
p++;
}
}
//p = arr;
printf("\n");
for (p = arr;p < arr+len;p++)
{
printf("%d ",*p);
}
return 0;
}