给定结构struct A { char t:4; char k:4; unsigned short i:8; unsigned long m; };问sizeof(A) = ?
by culuckyabcd - C/C++ - 2009-08-16 23:31:11 阅读(1560) 回复(7)
$ cat t.c
#include
定义:
char str[20] = "hello world!";
char* str1 = "hello world";
为什么
sizeof(str) = 20;
sizeof(str1) = 4;
何故?
根据我昨天在另一个帖子里请教的:
vector
int su; char ch[] = "1234"; su = sizeof(ch); 定义一个数组是不确定, 可我面试官竟然这样说: " su >= 5; " 我当时愣了????? 我还是认为 su = 5; 希望大家来说一下!!!!
定义了结构体 typedef struct { char m[5]; char n[10]; }a_t; 请问在没有声明实体变量的前提下可以用sizeof求出结构体中每个域的大小么, sizeof(a_t)是对的但sizeof(a_t.m)就错了,请问有好方法么 (注明:在没有申明实体变量的前提下)
一、sizeof的概念 sizeof是C语言的一种单目操作符,如C语言的其他操作符++、--等。它并不是函数。sizeof操作符以字节形式给出了其操作数的存储大小。操作数可以是一个表达式或括在括号内的类型名。操作数的存储大小由操作数的类型决定。 二、sizeof的使用方法 1、用于数据类型 sizeof使用形式:sizeof(type) 数据类型必须用括号括住。如sizeof(int)。 2、用于变量 sizeof使用形式...
#include
各位大侠,请教一下:
class a
{
int gg;
char b[19];
float f[2];
inline void test() {cout <<"test"<
if i have following declarations then - short S; long L; int I; char C; double D; sizeof(S+L+I+C+D) = ?
有一段代码如下: #include "stdio.h" void main(void){ class A {}; class B : virtual public A {}; class C: public A {}; class D: public B, public C {}; class E: virtual public B, virtual public C {}; printf("sizeof(A) = %d\n",sizeof(A)); printf("sizeof(B) = %d\n",sizeof(B)); printf("sizeof(C) = %d\n",sizeof(C)); printf("sizeof(D) = %d\n",sizeof(D)); printf("sizeof(E) = %d\n",sizeof(E)); } ...