Зміст курсу
C Basics
C Basics
Sizeof
Data Size
The sizeof()
function is a staple in C programming. It helps determine the size (in bytes) of the specified object or type.
For instance, let's see how many bytes the int
data type occupies:
main.c
The int
data type occupies 4 bytes.
Note
Bear in mind that different compilers might allocate varying byte sizes for the same data type.
Bits
A bit is the most basic unit of data a computer uses. Every byte consists of eight bits.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/fdbdf.png)
It was collectively decided by engineers to equate one byte to 8 bits because this configuration conveniently represents decimal numbers.
You've likely heard of the binary number system, which forms the foundation of computer operations.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/bdfbd.png)
At its essence, the goal is to represent numerical values we use in our daily lives using combinations of zeros and ones. Any number can be represented as a combination of powers of two.
For instance, the number 7 can be portrayed as "111", and here's the breakdown:
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/cvbcv.png)
The values 0 or 1 don't inherently have mathematical significance; they merely indicate a bit's state.
- 0 – the bit is inactive;
- 1 – the bit is active.
The number 113, in binary, appears as "01110001":
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/dfgdfg.png)
Data Types
What distinguishes different data types? – Their byte size!
Main.c
You can utilize the sizeof()
function on an array to ascertain its size:
main.c
An array with 10 integer elements occupies 40 bytes, meaning each individual element consumes 4 bytes. If you divide the total array size by the size of one of its elements, you'll determine the array's element count:
main.c
Все було зрозуміло?
Зміст курсу
C Basics
C Basics
Sizeof
Data Size
The sizeof()
function is a staple in C programming. It helps determine the size (in bytes) of the specified object or type.
For instance, let's see how many bytes the int
data type occupies:
main.c
The int
data type occupies 4 bytes.
Note
Bear in mind that different compilers might allocate varying byte sizes for the same data type.
Bits
A bit is the most basic unit of data a computer uses. Every byte consists of eight bits.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/fdbdf.png)
It was collectively decided by engineers to equate one byte to 8 bits because this configuration conveniently represents decimal numbers.
You've likely heard of the binary number system, which forms the foundation of computer operations.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/bdfbd.png)
At its essence, the goal is to represent numerical values we use in our daily lives using combinations of zeros and ones. Any number can be represented as a combination of powers of two.
For instance, the number 7 can be portrayed as "111", and here's the breakdown:
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/cvbcv.png)
The values 0 or 1 don't inherently have mathematical significance; they merely indicate a bit's state.
- 0 – the bit is inactive;
- 1 – the bit is active.
The number 113, in binary, appears as "01110001":
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/0472c1c8-2260-4847-940e-7678335677da/2/dfgdfg.png)
Data Types
What distinguishes different data types? – Their byte size!
Main.c
You can utilize the sizeof()
function on an array to ascertain its size:
main.c
An array with 10 integer elements occupies 40 bytes, meaning each individual element consumes 4 bytes. If you divide the total array size by the size of one of its elements, you'll determine the array's element count:
main.c
Все було зрозуміло?