sizeof()和strlen()的检测与对比
来源:互联网 发布:已连接,但无法访问网络 编辑:程序博客网 时间:2024/06/05 08:03
//*****sizeof函数的用法******
#include <iostream>
using namespace std;
void printValues(const int ia[], size_t size)
{
for (size_t i = 0; i != size; ++i)
{
cout << ia[i] << endl;
}
}
int main()
{
int j[] = {0,1};
printValues(j, sizeof(j) / sizeof(*j));
cout <<sizeof(j) <<endl;
cout <<sizeof(*j) <<endl;
cout <<endl;
cout <<"sizeof函数的检测:"<<endl;
char *str1 = "absde";
char str2[] = "absde";
char str3[8] = {'a'};
char str4[] = "0123456789";
cout <<"前面是sizeof(str1)"<<"\t"<<"后面的strlen(str1)函数作为对比的"<<endl;
cout<<"*str1:"<<sizeof(str1)<<"\t\t\t"<<strlen(str1)<<endl;
cout<<"str2:"<<sizeof(str2)<<"\t\t\t\t"<<strlen(str2)<<endl;
cout<<"str3:"<<sizeof(str3)<<"\t\t\t\t"<<strlen(str3)<<endl;
cout<<"str4:"<<sizeof(str4)<<"\t\t\t"<<strlen(str4)<<endl;
cout <<"同时检测到一个字符型占1个字节"<<endl;
cout <<endl;
int a = 123;
int *a1 = &a;
int a2[] = {1,2,3,4,5,6};
int a3[8] = {3};
int a4[] = {0,1,2,3,4,5,6,7,8,9};
cout <<"sizeof(a1): "<<sizeof(a1)<<endl;
cout <<"sizeof(a2): "<<sizeof(a2)<<endl;
cout <<"sizeof(a3): "<<sizeof(a3)<<endl;
cout <<"sizeof(a4): "<<sizeof(a4)<<endl;
cout <<"同时检测到一个整型占4个字节";
cout <<endl;
cout <<endl;
char const keyword[][10] = {"do","for","if","register","return","switch","while"};
cout<< sizeof(keyword)<<endl;//整个数组的长度
cout<< sizeof(keyword[0])<<endl;//每个元素所占的字节
cout<< sizeof(keyword) / sizeof(keyword[0])<<endl;//数组元素的个数
system("pause");
}
#include <iostream>
using namespace std;
void printValues(const int ia[], size_t size)
{
for (size_t i = 0; i != size; ++i)
{
cout << ia[i] << endl;
}
}
int main()
{
int j[] = {0,1};
printValues(j, sizeof(j) / sizeof(*j));
cout <<sizeof(j) <<endl;
cout <<sizeof(*j) <<endl;
cout <<endl;
cout <<"sizeof函数的检测:"<<endl;
char *str1 = "absde";
char str2[] = "absde";
char str3[8] = {'a'};
char str4[] = "0123456789";
cout <<"前面是sizeof(str1)"<<"\t"<<"后面的strlen(str1)函数作为对比的"<<endl;
cout<<"*str1:"<<sizeof(str1)<<"\t\t\t"<<strlen(str1)<<endl;
cout<<"str2:"<<sizeof(str2)<<"\t\t\t\t"<<strlen(str2)<<endl;
cout<<"str3:"<<sizeof(str3)<<"\t\t\t\t"<<strlen(str3)<<endl;
cout<<"str4:"<<sizeof(str4)<<"\t\t\t"<<strlen(str4)<<endl;
cout <<"同时检测到一个字符型占1个字节"<<endl;
cout <<endl;
int a = 123;
int *a1 = &a;
int a2[] = {1,2,3,4,5,6};
int a3[8] = {3};
int a4[] = {0,1,2,3,4,5,6,7,8,9};
cout <<"sizeof(a1): "<<sizeof(a1)<<endl;
cout <<"sizeof(a2): "<<sizeof(a2)<<endl;
cout <<"sizeof(a3): "<<sizeof(a3)<<endl;
cout <<"sizeof(a4): "<<sizeof(a4)<<endl;
cout <<"同时检测到一个整型占4个字节";
cout <<endl;
cout <<endl;
char const keyword[][10] = {"do","for","if","register","return","switch","while"};
cout<< sizeof(keyword)<<endl;//整个数组的长度
cout<< sizeof(keyword[0])<<endl;//每个元素所占的字节
cout<< sizeof(keyword) / sizeof(keyword[0])<<endl;//数组元素的个数
system("pause");
}
- sizeof()和strlen()的检测与对比
- strlen和sizeof的对比
- sizeof和strlen对比
- sizeof与strlen对比总结
- 对比C++中sizeof与strlen函数的区别
- sizeof和strlen的区别与联系
- strlen 和 sizeof的区别与解析
- sizeof与strlen的区别和不同
- sizeof()和strlen()的区别与联系
- sizeof与strlen的区别和联系
- strlen与sizeof的区别和用法
- sizeof和strlen的使用与区别
- sizeof与strlen对比小实验。。
- sizeof详解 sizeof与strlen的比较
- sizeof与strlen的区别
- sizeof()与strlen()的区别
- sizeof 与 strlen 的区别
- sizeof与strlen的区别
- Java多线程的相关机制
- 使用Tab controls window api 函数实现简单界面
- HDU 3127 WHUgirls (完全背包)
- ExecuteReader的用法
- 快速排序
- sizeof()和strlen()的检测与对比
- JVM参数调优
- HDU 1010 Tempter of the Bone
- Java中的String、StringBuilder,StringBuffer简析
- uva 10245 - The Closest Pair Problem(暴力剪枝)
- UVA 10194 Football (aka Soccer) 足球成绩统计 检索+模拟
- b3log的ArticleSender不是往本地数据库存文章的
- HDU 2097 Sky数
- HDU 2098 分拆素数和