码迷,mamicode.com
首页 > 其他好文 > 详细

sizeof 用法部分总结

时间:2017-04-24 12:29:17      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:class   pre   names   []   cout   struct   blog   用法   turn   

#include<iostream>
#include<string.h>
using namespace std;
struct s1
{
	char a[8];
};

struct s2
{
	double d;
};

struct s3
{
	s1 s;
	char a;
};

struct s4
{
	s2 s;
	char a;
};
struct s5
{
	int i : 8;
	int j : 4;
	int a : 3;
	double b;
};

int main(){
	
	int  *p1;
	cout << sizeof(p1) << endl;
	cout << sizeof(*p1) << endl;
	cout << "~~~~~~~~~~~~~~~~~~~~~~" << endl;
	char  *p2;
	cout << sizeof(p2) << endl;
	cout << sizeof(*p2) << endl;
	cout << "~~~~~~~~~~~~~~~~~~~~~~" << endl;
	int a[10];
	char b[] = "hello";
	string s = "hello";
	cout << sizeof(a) << endl;   //
	cout << sizeof(b) << endl;   //计算‘\0’
	cout << strlen(b) << endl;   //不计算‘\0‘
	cout << sizeof(s) << endl;
	cout << s.size() << endl;
	cout << s.capacity()<<endl;
	cout << "~~~~~~~~~~~~~~~~~~~~~~" << endl;
	cout << sizeof(s1) << endl; // 8
	cout << sizeof(s2) << endl; // 8
	cout << sizeof(s3) << endl; // 9
	cout << sizeof(s4) << endl; // 16;
	cout << sizeof(s5) << endl; // 16;
	system("pause");
	return true;
}

  

sizeof 用法部分总结

标签:class   pre   names   []   cout   struct   blog   用法   turn   

原文地址:http://www.cnblogs.com/wujufengyun/p/6755530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!