sizeof和strlen举例
来源:互联网 发布:遗传算法tsp代码 编辑:程序博客网 时间:2024/06/05 20:00
代码:
// SizeofTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"#include "memory.h"#include "stdlib.h"#include "string.h"typedef struct{ int x; int data[100]; double *pData;}TestSTR,*pTestSTR;int main(int argc, char* argv[]){ int a=12; printf("\nint a=12;sizeof(a)=%d\n",sizeof(a)); int b[10]={0}; printf("\nint b[10]={0};sizeof(b)=%d\n",sizeof(b)); double *p; printf("\ndouble *p;sizeof(p)=%d\n",sizeof(p)); p=new double[200]; printf("\ndouble *p;p=new double[200];sizeof(p)=%d,sizeof(*p)=%d\n",sizeof(p),sizeof(*p)); TestSTR varSTR; printf("\nstruct sizeof(TestSTR)=%d\n",sizeof(TestSTR)); printf("\nTestSTR varSTR; sizeof(varSTR)=%d\n",sizeof(varSTR)); varSTR.pData=new double[200]; printf("\nTestSTR varSTR; sizeof(varSTR)=%d\n",sizeof(varSTR)); printf("\nstruct point sizeof(pTestSTR)=%d\n",sizeof(pTestSTR)); pTestSTR var_pTestSTR; var_pTestSTR=&varSTR; printf("\npTestSTR var_pTestSTR; sizeof(var_pTestSTR)=%d\n",sizeof(var_pTestSTR)); printf("\npTestSTR var_pTestSTR; sizeof(*var_pTestSTR)=%d\n",sizeof(*var_pTestSTR)); memset(varSTR.pData,0,200*sizeof(double)); printf("\nTestSTR varSTR; sizeof(varSTR)=%d\n",sizeof(varSTR)); printf("-----------------------------------------------------\n"); char str[15]="nuptboyzhb"; char *pChar; pChar=str; printf("\nstrlen(str)=%d,sizeof(str)=%d\n",strlen(str),sizeof(str)); printf("\nstrlen(pChar)=%d,sizeof(pChar)=%d\n",strlen(pChar),sizeof(pChar)); return 0;}
运行结果:
int a=12;sizeof(a)=4
int b[10]={0};sizeof(b)=40
double *p;sizeof(p)=4
double *p;p=new double[200];sizeof(p)=4,sizeof(*p)=8
struct sizeof(TestSTR)=408
TestSTR varSTR; sizeof(varSTR)=408
TestSTR varSTR; sizeof(varSTR)=408
struct point sizeof(pTestSTR)=4
pTestSTR var_pTestSTR; sizeof(var_pTestSTR)=4
pTestSTR var_pTestSTR; sizeof(*var_pTestSTR)=408
TestSTR varSTR; sizeof(varSTR)=408
-----------------------------------------------------
strlen(str)=10,sizeof(str)=15
strlen(pChar)=10,sizeof(pChar)=4
Press any key to continue
- sizeof和strlen举例
- strlen 和 sizeof 的基本用法(举例)
- 关于sizeof和strlen的区别总结举例
- sizeof和strlen()
- 关于sizeof 和strlen
- sizeof 和 strlen区别
- strlen 和sizeof
- sizeof 和strlen
- strlen和sizeof
- strlen和sizeof
- sizeof 和strlen
- sizeof和strlen
- sizeof和strlen
- sizeof 和 strlen
- sizeof和strlen
- strlen和sizeof
- sizeof 和 strlen()
- sizeof和strlen
- oracle RACG
- 第九周实验报告(2)
- 第九周实验报告1.0
- BOJ 519
- 《第九周任务二》定义Time类中的<<和>>运算符的重载,实现时间输入输出,改造源程序中对运算结果的显示方式,使程序读起来更自然
- sizeof和strlen举例
- Oracle常用视图
- 为什么C++编译器不支持模板头文件和实现代码分离的编译
- Oracle 常用视图2
- 二叉树的基本操作
- POJ 2503
- 第九周任务1
- U880纯GPS定位综合解决方案,支持谷歌地图老虎地图百度地图
- getopt函数与getopt_long函数的用法