重温一下,最基础的知识。
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
int main(){
int i;
int *p;
p = (int*)malloc(sizeof(int));
int a[10]={0,1,2,3,4,5,6,7,8,9};
for(i = 0; i < 10; i++){
printf("%d ", a[i]);
}
free(p);
system("pause");
return 0;
}
头文件include <stdlib.h> 中stdlib 即standard library标准库。stdlib.h里面定义了五种类型、一些宏和通用工具函数。 类型例如size_t、wchar_t、div_t、ldiv_t和lldiv_t; 宏例如EXIT_FAILURE、EXIT_SUCCESS、RAND_MAX和MB_CUR_MAX等; 常用的函数如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等。
头文件#include <string.h> 不可以定义string s;可以用到strcpy等函数。
头文件#include <stdio.h> 中stdio 是 standard input output 的缩写,stdio.h 被称为“标准输入输出文件”,包含的函数大都和输入输出相关,printf() 就是其中之一。
头文件#include <stdint.h> 是 C99 中引进的一个标准C 库的头文件,
C99中,<stdint.h>中定义了几种扩展的整数类型和宏。规则如下(其中N可以为8,16,32,64):
1、整数类型被用于声明已知大小的整数,或显示特定特征的整数:
intN_t, int_leastN_t, int_fastN_t:表示长度为N位的整型数;
uintN_t, uint_leastN_t, uint_fastN_t表示长度为N位的无符号整型数 ;
2、stdint.h中的常量,定义以上各类型数的最大最小值(其中N可以为8,16,32,64)
INTN_MIN, UINTN_MIN, INTN_MAX, UINTN_MAX ;
INT_LEASEN_MIN, INT_LEASEN_MAX ;
INT_FASTN_MIN, INT_FASTN_MAX ;
既然是指针,那就顺便来点指针的的概念。
先看应用,再看概念。
指针既能交换两个变量的值,又能结合函数交换两变量的值, 也能指出数组最大值的下标,还可以进行地址算数运算。主要看自己想怎么玩。此外,指针直接访问地址,这个可以很好的进行硬件资源的管理。