指针是强类型的,需要特定类型的指针来存放特定类型变量的地址.
指针作用: 储存内存地址; 解引用那些地址的内容(访问和修改地址中的值)
一、整形,字符型指针输出:
#include <stdio.h>int main(int argc, const char* argv[])
{int a = 1025;int* p;p = &a;printf("size of integer is %d bytes\n", sizeof(int));printf("Address = %d,value = %d\n", p, *p);printf("Address = %d, value = %d\n", p + 1, *(p + 1));//算术运算char* p0;p0 = (char*)p;printf("size of cahr is %d bytes\n", sizeof(char));//字符型,最后一串只有一个字节,所以这里只打印出1// 1025 = 00000000 00000000 00000100 00000001printf("Address = %d, value = %d\n", p0,*p0);printf("Address = %d, value = %d\n", p0+1, *(p0+1));//算术运算
}
唯一的指针算术运算,以整数值的大小增加或减少指针值
二、void 类型的声明:
只可以打印其中的地址,
取其中的值和进行算术运算都会导致程序无法运行.
int main(int argc, const char* argv[])
{int a = 1025;int* p;p = &a;//printf("size of integer is %d bytes\n", sizeof(int));//printf("Address = %d,value = %d\n", p, *p);//printf("Address = %d, value = %d\n", p + 1, *(p + 1));void* p0;p0 = p;printf("Address = %d", p0);
}