当前位置:编程学习 > C#/ASP.NET >>

asp.net sizeof的用法

asp教程.net sizeof

简介
  Pascal的一种内存容量度量函数:
C语言中判断数据类型长度符
编辑本段用法
  Var   
a : array[1..10000] of longint;   
Begin   Writeln(SizeOf(a));   
End.   
输出:40000   
如果定义Integer,
则输出:20000   
c语言中判断数据类型长度符的关键字   
用法   
sizeof(类型说明符,数组名或表达式);   
或   
sizeof 变量名   
1. 定义:   
sizeof是C/C++中的一个操作符(operator),简单的说其作用就是返回一个对象或者类型所占的内存字节数。

#include <iostream>
using namespace std;
 
int main()
{
  char ch;
  int i;
 
  cout << sizeof ch << ' '; // size of char
  cout << sizeof i << ' ';  // size of int
  cout << sizeof (float) << ' '; // size of float
  cout << sizeof (double) << ' '; // size of double
 
  return 0;
}

实例二

#include<iostream.h>

union u_tag{
   int i;
   double d;
}u={88};
struct s_tag{
    int i;
       double d;
}s={66,1.234};

int main()
{
    int size;
       size=sizeof(union u_tag);
    cout<<"sizeof(union u_tag)="<<size<<endl;
    u.i=100;
       cout<<"u.i="<<u.i<<endl;
       u.d=1.2345;
       cout<<"u.d="<<u.d<<endl;
       size=sizeof(u.d);
       cout<<"sizeof(u.d)="<<size<<endl;
       cout<<"s.i="<<s.i<<endl;
       cout<<"s.d="<<s.d<<endl;
       size=sizeof(struct s_tag);
       cout<<"sizeof(struct s_tag)="<<size<<endl;
}

sizeof类

#include <iostream>

class EmptyClass {
};

int main()
{
    std::cout << "sizeof(EmptyClass): " << sizeof(EmptyClass)
              << 'n';
}

补充:asp.net教程,.Net开发 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,