当前位置:网站首页>【C语言】详解 C 语言获取数组长度
【C语言】详解 C 语言获取数组长度
2022-06-28 06:40:00 【嵌入式职场】
1、使用 sizeof 关键字
用 sizeof 可以获得数据类型或变量在内存中所占的字节数。
同样,用 sizeof 也可以获得整个数组在内存中所占的字节数。
因为数组中每个元素的类型都是一样的,在内存中所占的字节数都是相同的,所以总的字节数除以一个元素所占的字节数就是数组的长度。
2、程序实例
#include <stdio.h>
int main(){
//定义数组
int arr[30];
//求数组长度
int n = sizeof(arr)/ sizeof(arr[0]);
printf("数组长度为: n=%d\n",n);
return 0;
}
边栏推荐
- 4~20ma input /0~5v output i/v conversion circuit
- JDBC学习(一)——实现简单的CRUD操作
- 语音增强-频谱映射
- 链表(三)——反转链表
- Linux MySQL implements root user login without password
- Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
- 报错--解决core-js/modules/es.error.cause.js报错
- @RequestParam
- 微信小程序编译页面空白bug的原因
- Puge -- understanding of getordefault() method
猜你喜欢

pytorch RNN 学习笔记

Linked list (I) - remove linked list elements

Freeswitch uses Mod_ Shot module plays mp3

D3D11_ Chili_ Tutorial (3): design a bindable/drawable system

RN7302三相电量检测(基于STM32单片机)

Speech enhancement - spectrum mapping

Linked list (III) - reverse linked list

Boost the rising point | yolov5 combined with alpha IOU

Camx架构开UMD、KMD log以及dump图的方式

异常处理(一)——空指针和数组索引越界
随机推荐
Niubi 666, this project makes web page making as simple as building blocks
[digital statistics DP] counting problem
Mise en œuvre de l'actionneur asynchrone d'exécution à partir de zéro
MySQL(二)——基本操作
Configure redis from 0
Promotion intégrale et ordre des octets de fin de taille
Use the SQL SELECT count distinct query statement to count the total number of unique values of a field in the database
Shell script one click deployment (MySQL)
Caused by: com. fasterxml. jackson. databind. exc.InvalidDefinitionException: Cannot construct instance
eyebeam高级设置
VM332 WAService. js:2 Error: _ vm. Changetabs is not a function
fpm工具安装
AutoCAD C# 多段線小銳角檢測
Install and manage multiple versions of PHP under mac
Freeswitch uses origin to dialplan
[rust translation] implement rust asynchronous actuator from scratch
小程序页面设置100%高度还是留白怎么办?
[interval DP] stone consolidation
js正则表达式系统讲解(全面的总结)
freeswitch使用mod_shout模块播放mp3