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

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

王林
Release: 2023-09-06 12:37:06
forward
668 people have browsed it

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;
}
Copy after login

Output

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template