#define _CRT_SECURE_NO_WARNINGS//强行去掉安全检查
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
void main()
{
char *p = NULL;
char buf[] = "chenqi";
printf("p1=%d\n", p);
//改变指针变量的值
p = buf;
printf("p2=%d\n", p);
//指针变量,和指向的内存是两个不同的概念
p = p + 1;//改变了指向变量的值,改变了指针的指向
printf("p3=%d\n", p);
printf("buf1=%s\n", buf);
printf("*p=%c", *p);
printf("改变指针指向的内存数据,并不会影响到指针的值\n");
//指针变量指向的内存数据发生变化,不会影响指针的值
buf[1] = '1';
printf("p4=%d\n", p);
printf("buf2=%s\n", buf);
//指针变量可以修改指针指向的内存数据的值,不会影响指针变量原来指向的地址
*p = 'm';
printf("p5=%d\n", p);
printf("buf3=%s\n", buf);
//写内存时,一定要确保内存可写
char *buf2 = "chenqi 6666";//文字常量区,内存不可改
//buf2[2] = 'q'; //err
char buf3[] = "chenqi 7777";
buf3[2] = '8'; //ok
//6.不允许向NULL和未知非法地址
//拷贝内存
char *p3 = NULL;
//给p3指向的内存区域拷贝内存
//给指针一个地址
p3 = buf3;
strcpy(p3, "7777"); //err
system("pause");
}
//----
//#define _CRT_SECURE_NO_WARNINGS//强行去掉安全检查
//#include<stdio.h>
//#include<stdlib.h>
//#include<Windows.h>
////指针变量和指针所指向的内存是两个不同的概念
//void main()
//{
// char *p = NULL;
// char buf[] = "chenqi";
// char buf2[] = "aaaaaa";
// printf("p1=%d\n", p);
// //改变指针变量的值
// p = buf;
// printf("p2=%d\n", p);
//
// //改变指针的指向
// p = buf2;
// printf("buf2=%s\n", buf2);
// printf("p3=%d\n", p);
// buf2[0] = 'z';
// *p = 'c';
// printf("\n\n%c\n", *p);
// system("pause");
//}
#include<stdio.h>
#include<stdlib.h>
#include<Windows.h>
void main()
{
char *p = NULL;
char buf[] = "chenqi";
printf("p1=%d\n", p);
//改变指针变量的值
p = buf;
printf("p2=%d\n", p);
//指针变量,和指向的内存是两个不同的概念
p = p + 1;//改变了指向变量的值,改变了指针的指向
printf("p3=%d\n", p);
printf("buf1=%s\n", buf);
printf("*p=%c", *p);
printf("改变指针指向的内存数据,并不会影响到指针的值\n");
//指针变量指向的内存数据发生变化,不会影响指针的值
buf[1] = '1';
printf("p4=%d\n", p);
printf("buf2=%s\n", buf);
//指针变量可以修改指针指向的内存数据的值,不会影响指针变量原来指向的地址
*p = 'm';
printf("p5=%d\n", p);
printf("buf3=%s\n", buf);
//写内存时,一定要确保内存可写
char *buf2 = "chenqi 6666";//文字常量区,内存不可改
//buf2[2] = 'q'; //err
char buf3[] = "chenqi 7777";
buf3[2] = '8'; //ok
//6.不允许向NULL和未知非法地址
//拷贝内存
char *p3 = NULL;
//给p3指向的内存区域拷贝内存
//给指针一个地址
p3 = buf3;
strcpy(p3, "7777"); //err
system("pause");
}
//----
//#define _CRT_SECURE_NO_WARNINGS//强行去掉安全检查
//#include<stdio.h>
//#include<stdlib.h>
//#include<Windows.h>
////指针变量和指针所指向的内存是两个不同的概念
//void main()
//{
// char *p = NULL;
// char buf[] = "chenqi";
// char buf2[] = "aaaaaa";
// printf("p1=%d\n", p);
// //改变指针变量的值
// p = buf;
// printf("p2=%d\n", p);
//
// //改变指针的指向
// p = buf2;
// printf("buf2=%s\n", buf2);
// printf("p3=%d\n", p);
// buf2[0] = 'z';
// *p = 'c';
// printf("\n\n%c\n", *p);
// system("pause");
//}