sizeof

    0热度

    1回答

    考虑这两个方案: //////////////////////计划1 //////////// void print(int arr[]) { int *p=arr; cout<< sizeof(arr)<<endl; //// here it is 8 } int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8}; print(arr)

    0热度

    2回答

    程序下面产生 输出 - 1 4 4 #include<stdio.h> void main() { char ch; ch='A'; printf("%d %d %d\n",sizeof(ch),sizeof('A'),sizeof(3.2f)); } 为什么是字符常数的大小为4个字节?

    4热度

    1回答

    我试图静态分配一些结构,每个结构包含两个成员:一个指向结构数组的指针,以及该数组的大小。 下面的代码的工作版本: #define ARRAY_SIZE(x) (sizeof((x))/sizeof((x)[0])) struct conf_element { char *key; enum conf_elem_type val_type; void *val

    0热度

    2回答

    我认为这个问题应该由社区来识别和解决,但似乎我在用错误的关键字搜索,或者它确实是难以捉摸的。 问题很简单。我想定义一个结构,其中应该定义一个动态数据容器(Vector,List,Queue,无论什么作品)。 #pragma pack(1) struct Example { int foo; QVector<int> bar; }; 我需要插入整数值到此向量(或采取

    0热度

    1回答

    对于通用的方法来找到一个向量元素的大小,这是有效的: std::vector<float> some_vector; int size = sizeof(some_vector[0]); 或者可能这会导致问题,因为some_vector [0]可能是空的? 无论如何,我猜这是在编译期间评估的,但是它是按照标准吗?

    2热度

    3回答

    printf("Enter name: "); scanf("%s", first); int s = sizeof(first); for(i = 0; i < s; i++){ if(s < 2 || s > 20){ printf("improper array size"); } } fprintf(fptr,"NAME: %s \n",first

    0热度

    2回答

    我必须定义一个结构与不安全的代码一起工作,所以我必须设置每个字段的FieldOffset值。但是我无法定义指针的大小。下面是代码: [StructLayout(LayoutKind.Explicit)] public struct SomeStructO { public SomeStructO(int theNumber) { TheNumber = theN

    1热度

    2回答

    当数组为空时,ARRAY_SIZE是否返回未定义的行为?因为我们做了一个未知的分区sizeof((X)[0]) #include <stdio.h> #include <stdlib.h> #include <string.h> #ifndef ARRAY_SIZE #define ARRAY_SIZE(X) sizeof((X))/sizeof((X)[0]) #endif st

    0热度

    1回答

    Code 1 #include <stdio.h> int T; int main() { struct T{ double x;}; printf("%d", sizeof(T)); return 0; } 输出:4 Code 2 #include <stdio.h> struct T{ double x;}; int main() {

    0热度

    1回答

    在此以下的代码: #include<stdio.h> int main(void) { printf("%d",sizeof(int)); return 0; } 当上的gcc编译(Ubuntu的4.8.4-2ubuntu1〜14.04.3)4.8.4编译它给出警告: 格式 '%d' 预计参数类型'int',但参数2的类型为 'long unsigned int'[-