标签:大小 reg case char rcm include color pre int
指针数组
指针数组是数组,指针数组每个元素是一个指针
指针数组的定义:type* parray[n];
type* 是数组中每个元素的类型
parray 为数组名
n为大小
例子:
float* a[3] //a是一个数组,每个元素的类型是float*
code:
#include <stdio.h> #include <string.h> #define DIM(a) (sizeof(a)/sizeof(*a)) int lookup_keyword(const char* key, const char* table[], const int size) { int ret = -1; int i = 0; for(i=0; i<size; i++) { if( strcmp(key, table[i]) == 0 ) { ret = i; break; } } return ret; } int main() { const char* keyword[] = { "do", "for", "if", "register", "return", "switch", "while", "case", "static" }; printf("%d\n", lookup_keyword("return", keyword, DIM(keyword))); printf("%d\n", lookup_keyword("main", keyword, DIM(keyword))); return 0; }
标签:大小 reg case char rcm include color pre int
原文地址:https://www.cnblogs.com/sea-stream/p/10994958.html