#include <iostream>
int main()
{
char t1[] = {'H','e','l','l','o','\0'};
char t2[] = "Hello";
char t3[] = "Hello";
char *s1 = "Hello";
char *s2 = "Hello";
void *v1 = t1, *v2 = t2, *v3 = t3, *v4 = s1, *v5 = s2;
std::cout <<v1<<'\t'<<v2<<'\t'<<v3<<'\t'<<v4<<'\t'<<v5<<std::endl;
0xbffff460 0xbffff450 0xbffff440 0x8048844 0x8048844
*t1 = 'x'; *t2 = 'q'; *ct = 'y';
*s1 = 'w'; *s2 = 'z';
return 0;
}
#include <iostream>
int main()
{
char t[] = "Hello";
const char ct[] = "Hello";
char *s1 = "Hello";
const char *s2 = "Hello";
2_const.cpp: In function `int main()':
2_const.cpp:12: warning: invalid conversion from `const void*' to `void*'
2_const.cpp:17: assignment of read-only location
void *v1 = t, *v2 = ct, *v3 = s1, *v4 = s2;
std::cout << v1 << '\t' << v2 << '\t' << v3 << '\t' << v4 << std::endl;
*t = 'x'; *ct = 'y'; *s1 = 'w'; *s2 = 'z';
return 0;
}
#include <iostream>
int main()
{
char t[] = "Hello";
const char *s1 = "Hello";
*t = 'x';
*s1 = 'w';
return 0;
}
3_const.cpp: In function `int main()':
3_const.cpp:12: assignment of read-only location
#include <iostream>
int f(const int i)
{
return i;
}
int main()
{
const int c1 = 1;
const int c2 = 2;
const int c3 = f(3);
const int *p = &c2;
int t1[c1];
int t2[c2];
int i; std::cin >> i;
switch(i)
{
case c1: std::cout << "c1"; break;
case c2: std::cout << "c1"; break;
}
return 0;
}