C11
这篇文章写的很好:点击打开链接
const char* a[]={"a","b","c"}; 定义数组
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char shuru;
const char* a[] = { "1", "2", "3" };
const char b[] = { 'a', 'b', 'c', 'd' };
cout << a[1] << endl;
cout << b << endl;
cin >> shuru;
return 0;
}
abcd烫烫烫烫t芙
改成
printf("\n%s\n",b);
依然会出现汉子
将定义a数组的“”改成‘’会报错
#include <iostream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char shuru;
const char* a[] = { "1", "2", "3" };
cout << a[1] << endl;
printf("%s", a[1]);
const char b[4] = { 'a', 'b', 'c', 'd' };
const int intb[4] = { 1, 2, 3, 4 };
cout << b[3]<<endl;
const char c = 'd';
cout << c << endl;
const string d[] = { "1", "2", "3" };
cout << d[1] << endl;
string e = "I'm e!";
cout << e << endl;
char *ch = "I'm ch!";
cout << ch << endl;
cout << sizeof(a[1])<<endl;
char s2[] = "hello";
cout << sizeof(s2) << endl;
const char* newa[] = {"a", "b", "ccc", "dd" };
cout << newa[2] << endl;
newa[2] = "ccccc";
cout << newa[2] << endl;
char* ff = "I'm f!";
char* f = ff;
printf("字符串起始地址值:%p\n", f);
printf("字符串起始地址值:%p\n", ff);
f = "www";
printf("字符串起始地址值:%p\n", f);
printf("字符串起始地址值:%p\n", ff);
cout << f << endl;
char* p1 = "anything";
char* p2 = "anything";
char p3[] = "anything";
printf("p1 = %x, p2 = %x,p3 = %x \n", p1, p2,p3);
cin >> shuru;
return 0;
}