#include<iostream>#include<stdio.h>
using namespace std;
{
cout << sizeof(str)<<endl; //4 数组名当为形参传递时,相当指向
//数组首元素首地址的指针,这是避免拷贝
//浪费内存
}
int main (int argc,char *argv[])
{
char element ;
element = 'a';
cout <<sizeof(&element)<<endl;
int *p = NULL;
int a = 9;
p = &a;
/* 强制类型转换()与sizeof() 优先级是同一级别 */
//cout <<sizeof((int )* *p);//错误
cout <<sizeof(int ) * *p<<endl; //4*9 == 36
cout <<sizeof((int *)p)<<endl; //指针的大小
char *q = NULL;
char des = 'a';
q = &des;
cout<< sizeof(q)<<endl; //指针的大小
cout <<sizeof(*q)<<endl; //指类的大小
int str[10];
cout <<sizeof(str)<<endl; //整个数组的大小,数组名为数组的整个空间大小
cout <<sizeof(str[9])<<endl; //第10个元素的大小,
cout << sizeof(&str)<<endl; //40
cout << sizeof(&str[0])<<endl; //4
fun(str);
return 0;
}
<span style="font-size:18px;">#include<iostream>
#include<stdio.h>
using namespace std;
void fun (int str[10])
{
cout << sizeof(str)<<endl; //4 数组名当为形参传递时,相当指向
//数组首元素首地址的指针,这是避免拷贝
//浪费内存
}
int main (int argc,char *argv[])
{
char element ;
element = 'a';
cout <<sizeof(&element)<<endl;
int *p = NULL;
int a = 9;
p = &a;
/* 强制类型转换()与sizeof() 优先级是同一级别 */
//cout <<sizeof((int )* *p);//错误
cout <<sizeof(int ) * *p<<endl; //4*9 == 36
cout <<sizeof((int *)p)<<endl; //指针的大小
char *q = NULL;
char des = 'a';
q = &des;
cout<< sizeof(q)<<endl; //指针的大小
cout <<sizeof(*q)<<endl; //指类的大小
int str[10];
cout <<sizeof(str)<<endl; //整个数组的大小,数组名为数组的整个空间大小
cout <<sizeof(str[9])<<endl; //第10个元素的大小,
cout << sizeof(&str)<<endl; //40
cout << sizeof(&str[0])<<endl; //4
fun(str);
return 0;
}</span>
#include<iostream>
#include<stdio.h>
using namespace std;
void fun (int str[10])
{
cout << sizeof(str)<<endl; //4 数组名当为形参传递时,相当指向
//数组首元素首地址的指针,这是避免拷贝
//浪费内存
}
int main (int argc,char *argv[])
{
char element ;
element = 'a';
cout <<sizeof(&element)<<endl;
int *p = NULL;
int a = 9;
p = &a;
/* 强制类型转换()与sizeof() 优先级是同一级别 */
//cout <<sizeof((int )* *p);//错误
cout <<sizeof(int ) * *p<<endl; //4*9 == 36
cout <<sizeof((int *)p)<<endl; //指针的大小
char *q = NULL;
char des = 'a';
q = &des;
cout<< sizeof(q)<<endl; //指针的大小
cout <<sizeof(*q)<<endl; //指类的大小
int str[10];
cout <<sizeof(str)<<endl; //整个数组的大小,数组名为数组的整个空间大小
cout <<sizeof(str[9])<<endl; //第10个元素的大小,
cout << sizeof(&str)<<endl; //40
cout << sizeof(&str[0])<<endl; //4
fun(str);
return 0;
}
#include<iostream>
#include<stdio.h>
using namespace std;
void fun (int str[10])
{
cout << sizeof(str)<<endl; //4 数组名当为形参传递时,相当指向
//数组首元素首地址的指针,这是避免拷贝
//浪费内存
}
int main (int argc,char *argv[])
{
char element ;
element = 'a';
cout <<sizeof(&element)<<endl;
int *p = NULL;
int a = 9;
p = &a;
/* 强制类型转换()与sizeof() 优先级是同一级别 */
//cout <<sizeof((int )* *p);//错误
cout <<sizeof(int ) * *p<<endl; //4*9 == 36
cout <<sizeof((int *)p)<<endl; //指针的大小
char *q = NULL;
char des = 'a';
q = &des;
cout<< sizeof(q)<<endl; //指针的大小
cout <<sizeof(*q)<<endl; //指类的大小
int str[10];
cout <<sizeof(str)<<endl; //整个数组的大小,数组名为数组的整个空间大小
cout <<sizeof(str[9])<<endl; //第10个元素的大小,
cout << sizeof(&str)<<endl; //40
cout << sizeof(&str[0])<<endl; //4
fun(str);
return 0;
}