当前位置:网站首页>[C language] detailed explanation of C language to obtain array length
[C language] detailed explanation of C language to obtain array length
2022-06-28 06:43:00 【Embedded workplace】
1、 Use sizeof keyword
use sizeof You can get the number of bytes the data type or variable occupies in memory .
Again , use sizeof You can also get the number of bytes the entire array occupies in memory .
Because the type of each element in the array is the same , The number of bytes in memory is the same , So the total number of bytes divided by the number of bytes occupied by an element is the length of the array .
2、 Program instance
#include <stdio.h>
int main(){
// Define an array
int arr[30];
// Find array length
int n = sizeof(arr)/ sizeof(arr[0]);
printf(" The array length is : n=%d\n",n);
return 0;
}
边栏推荐
- 调接口事件API常用事件方法
- AttributeError: 'callable_ iterator' object has no attribute 'next'
- VM332 WAService.js:2 Error: _vm.changeTabs is not a function报错
- Parsing ng template with let total in NZ Pagination
- ROS rviz_ Satellite function package visualizes GNSS track and uses satellite map
- 整型提升和大小端字节序
- Linked list (II) - Design linked list
- EasyUI reset multi condition query
- AutoCAD C# 多段線小銳角檢測
- CAD二次开发+NetTopologySuite+PGIS 引用多版本DLL问题
猜你喜欢

Causes of wechat applet compilation page blank bug

职场IT老鸟的几点小习惯

Linux MySQL implements root user login without password

Some habits of it veterans in the workplace

图片按日期批量导入WPS表格

AutoCAD C polyline small acute angle detection

Integer promotion and size side byte order

Alert pop-up processing in Web Automation

代码没写错,渲染页面不显示原因

「杰伦熊」暴跌96.6% 明星带货NFT为何遇冷?
随机推荐
浮动与定位
Caused by: com. fasterxml. jackson. databind. Exc.invalidformatexception: exception resolution
Students who do not understand the code can also send their own token. The current universal dividend model can be divided into BSC and any generation B
Mise en œuvre de l'actionneur asynchrone d'exécution à partir de zéro
Configure redis from 0
CRC32概述以及实现和使用
编译原理期末复习
【Paper Reading-3D Detection】Fully Convolutional One-Stage 3D Object Detection on LiDAR Range Images
报错--解决core-js/modules/es.error.cause.js报错
Puge -- singleton mode
JDBC学习(一)——实现简单的CRUD操作
Introduction to Qualcomm platform WiFi -- Wi Fi display software
ROS rviz_ Satellite function package visualizes GNSS track and uses satellite map
AttributeError: 'callable_ iterator' object has no attribute 'next'
FPGA - 7系列 FPGA SelectIO -08- 高级逻辑资源之OSERDESE2
Puge -- three basic sorting, bubbling, selection and quickness
Camx架构开UMD、KMD log以及dump图的方式
【Rust日报】2020-05-24 Rash, Rocket, Mun, Casbin
FPGA - 7 Series FPGA selectio -09- io of advanced logic resources_ FIFO
Eyebeam advanced settings