Home  >  Article  >  Backend Development  >  How to find the size of int in C/C++?

How to find the size of int in C/C++?

王林
王林forward
2023-09-06 12:37:06568browse

How to find the size of int in C/C++?

In this section we will learn how to get size of integer array in C or C? The size of an int[] is basically counting the number of elements within that array. To get this we can use sizeof() operator. If you pass an array name in sizeof() then it will return the total size of the memory block occupied by the array. Now, if we divide this by the size of each element, we get the number of elements.

Let's see the example below to understand it better.

Example
#include <iostream>
using namespace std;
int main() {
   int data[] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 91, 82, 73, 64};
   cout << "Memory occupied by data[]: " << sizeof(data) << endl;
   cout << "Size of data[] array: " << sizeof(data)/sizeof(data[0]) << endl;
}

Output

Memory occupied by data[]: 52
Size of data[] array: 13

The above is the detailed content of How to find the size of int in C/C++?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete