1:字符數組是一個一維數組,引用字符數組的指針為字符指針,字符指針就是指向字符型內存空間的指針變量。
char *p;
char *string="www.mingri.book";
2:實例,通過指針連接兩個字符數組,代碼如下:

// 6.14.cpp : 定義控制台應用程序的入口點。 // #include "stdafx.h" #include<iostream> using namespace std; void main() { char str1[50], str2[30], *p1, *p2; p1 = str1; p2 = str2; cout << "please input string1:" << endl; gets_s(str1);//這種輸入方式將‘\0’作為結束符,而不是空格鍵 cout << "please input string2:" << endl; gets_s(str2); while (*p1 != '\0') p1++; while (*p2 != '\0') *p1++ = *p2++; *p1 = '\0'; cout << "the new string is:" << endl; puts(str1); }
運行結果: