Chinaunix首页 | 论坛 | 博客
  • 博客访问: 199118
  • 博文数量: 36
  • 博客积分: 2501
  • 博客等级: 少校
  • 技术积分: 420
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-18 23:27
个人简介

时间就是一切。

文章分类

全部博文(36)

文章存档

2023年(1)

2017年(2)

2016年(6)

2014年(1)

2009年(1)

2008年(15)

2007年(10)

我的朋友

分类: C/C++

2017-08-13 11:32:16

#include "stdio.h"
#include "../include/Point_Test.h"


//error
void swapError(int *p, int *q)
{
int *t;//空指针


*t=*p;//这里不能这样赋值
*p=*q;
*q=*t;


return;
}


// int a, int b, p, q 的值统统交换
void swap(int *p, int *q)
{
int t;


t=*p;
*p=*q;
*q=t;


return;
}


//int a, int b 的值不变, p,q 的值会交换
void swap1(int **p, int **q)
{
int *t;


t=*p;
*p=*q;
*q=t;


return;
}


//返回值是什么?
int fun(int *p)
{
return *p;//返回指针地址所存储的值
}




//函数指针
void (*pfun)(int x);
void FileFunc(int a),EditFunc(int b);
void FileFunc(int a)
{
printf("FileFunc a=%d\n",a);
}


void EditFunc(int b)
{
    printf("EditFunc  b=%d\n",b);
}




int main( void )
{
int a=1,b=2,*p=&a,*q=&b;
signed int index = 0;
signed int sum = 0;
signed int max = 100;
signed int value = 0;
int *i_p = NULL;
char *c_p = NULL;
int **i_pp = NULL;
int (*pp_p)[3] = { NULL };
int *(*fp_p)[4] = { NULL };


char static sttest[]="HELLO WORLD!";
static char sttest1[]="HELLO WORLD!";
char const cttest[]="HELLO WORLD!";
const char cttest1[]="HELLO WORLD!";
static char *ststr="HELLO WORLD!";
char static *ststr1="HELLO WORLD!";
const char *ctstr="HELLO WORLD!";
char const *ctstr1="HELLO WORLD!";


pfun=FileFunc;
(*pfun)(1);
pfun=EditFunc;
(*pfun)(2);


a=fun(p);


sttest[5]='-';
sttest1[5]='-';
//cttest[5]='-';//const 不允许修改
//cttest1[5]='-'; //const 不允许修改
//*ststr='h';//字符串常量是不允许修改的
//*ctstr1='h'; //const 不允许修改


swap(p,q);// a, b, p, q 的值统统交换
swap1(&p,&q);//a,b 的值不变, p,q 的值会交换


swap(&a,&b);// a, b, p, q 的值统统交换




#if TEST_1
char a[20] = "You_are_a_girl";
char *p = a;
char **ptr = &p;

printf(" **ptr = %c\n", **ptr ); //这里输出 Y 
ptr++; //这里是 ptr 指针变化,而不是 ptr 指针所指的值(p 指针)的变化。所以下面的输出就不确定,或非法访问等等。
printf(" **ptr = %c\n", **ptr ); //这里就所不清楚了
#endif
scanf("%d",&a);
return 0;
}

阅读(1193) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~