sizeof 问答列表

如何找到数组的大小(从指向第一个元素数组的指针)?

作者:jkidv 提问时间:1/30/2009

首先,这里有一些代码: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf("%u\n", sizeof(days)...

为什么从函数内部计算数组的大小不正确?

作者:Neeraj-Kumar-Coder 提问时间:1/4/2021

当我在函数中使用此代码时,数组的大小(或长度)被正确计算:main() #include <stdio.h> int main(void) { int arr[] = {2, 5, 9, 8, ...

为什么我应该在sizeof()中使用void *而不是显式指针类型?

作者:Hobbes 提问时间:5/13/2023

我在 StackOverflow 答案 (https://stackoverflow.com/a/3331268/17342809) 下阅读了这条评论: 内存分配请求应尽可能与类型无关:不要对内存分...

Arduino (ESP32) - Struct-Size 和输出混淆

作者:Bernd Klein 提问时间:10/29/2023

我尝试在 EPS32 上将结构转换为字节流。 在我的结构/联合下面。 #include <Arduino.h> typedef struct { uint16_t header; float ...

计算长数组SIZE_MAX元素的大小

作者:Some Name 提问时间:10/28/2023

请考虑以下代码: #include <stdio.h> #include <limits.h> #include <inttypes.h> #include <stddef.h> int main...

如何找到数组的大小(从指向第一个元素数组的指针)?

作者:jkidv 提问时间:1/30/2009

首先,这里有一些代码: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf("%u\n", sizeof(days)...

将size_t分配给off_t会产生符号转换错误

作者:Some Name 提问时间:10/13/2023

我正在使用以下版本的 gcc: $ gcc --version gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 请考虑以下简单的代码片段:-Werror=sign...

多级继承和空基优化中的内存布局

作者:Kirill Afentev 提问时间:10/10/2023

请考虑以下继承: struct Empty {}; struct A: Empty { int64_t a; int8_t b; }; struct B: A { int32_t c; }...

是否可以获取函数 fread() 的字符串大小

作者:ben 提问时间:10/9/2023

我需要获取字符串的大小以传递给函数 read() 下面是我尝试实现的代码,使用函数 size 查找字符串的大小,但它不起作用 #include <stdlib.h> int main() { ...

分配数组,使用 for 循环初始化给定的任何分配大小

作者:Shaler 提问时间:9/26/2023

int *p_numbers; p_numbers = malloc((sizeof *p_numbers) * 10); if (p_numbers == NULL) exit(EXIT_F...


共19条 当前第1页