#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
void funct(char* p)
{
cout<<"funct(char* p); sizeof(p)="<<sizeof(p)<<endl;
}
void main(void)
{
// sizeof 和strlen 的区别 及在指针与数组中的不同结果
char *p = "123456789";
cout << "sizeof(p) = " << sizeof(p) << endl; // sizeof(p) = 4 指针的位数;指针在32位机子上长度是4字节的
cout << "strlen(p) = " << strlen(p) << endl; // strlen(p) = 9
char str[] = "123456789";
cout << "sizeof(str) = " << sizeof(str) << endl; //sizeof(str) = 10 加上一个'/0'
cout << "strlen(str) = " << strlen(str) << endl; //strlen(str) = 9
funct(str); // funct(char* p); sizeof(p)=4;
//指针与数组的差别
// p[1] = '8'; error, 指针的值不能改变,(注:编译可通过,但运行失败!)
str[5] = '9'; // right, 数组的值可以改变
// void *p;
void *void_p = malloc(100);
cout << "sizeof(void_p) = " << sizeof(void_p) << endl; //sizeof(void_p) = 4, 指针的位数
char *char_p = NULL;
cout << sizeof(*char_p) << endl; // sizeof(*char_p) = 1;
getchar();
}