How to determine or get array length (size) in C/C++

How to determine or get array length (size) in C/C++

ProgrammerTube

8 лет назад

80,684 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Dev_ TROY
Dev_ TROY - 26.01.2023 23:58

I feel like you're mosh hamadani, am I right ??

Ответить
Hannibaal Barça
Hannibaal Barça - 25.11.2022 21:06

This work only on stack allocation, allocation in free memory it should be defined by user in some manner of vector stl .

Ответить
Motivation with Lorrie
Motivation with Lorrie - 04.08.2022 06:12

Beautiful explanation. Thank you so much!

Ответить
Andrew Park
Andrew Park - 05.02.2022 04:55

what if we declare array[100] in the beginning and if we only input 15 values into the array, how are we supposed to get the length of the array? If I do that sizeof thing I will get 100, but I want 15.

Ответить
Danson BTG
Danson BTG - 29.01.2022 02:09

is ar already known to be array? why does it work when u divide size of ar instead of size of a?

Ответить
Lot Pot
Lot Pot - 07.10.2021 04:44

so there's no any built function for that
? 😢

Ответить
Manohar Nookala
Manohar Nookala - 24.09.2021 05:12

Hi, i have size like 20, and in the array few element(s) i have. then how to find the length. i dont want to count junk elements.

Ответить
Jose Raul
Jose Raul - 16.02.2021 18:24

Nice mate!!!

Ответить
C Will
C Will - 22.07.2020 19:57

Good video, but why is C++ such butt?

Ответить
jzzj eight
jzzj eight - 26.05.2020 13:49

wow thank you holy shit i was going crazy, like how the fk is the array size 12 if it only has 3 elements, u made it clear thanks

Ответить
IamExile
IamExile - 04.01.2020 15:04

in c++ I can't put AR[ ]
You use it on C how to use it in c++

Ответить
Limitless 1
Limitless 1 - 01.10.2019 16:10

That is a cool stunt :)

Ответить
Ian Prado
Ian Prado - 10.08.2019 20:28

Great Video!

Ответить
Sushant Shakya
Sushant Shakya - 26.05.2019 12:59

AWESOME

Ответить
Ali Ahmad
Ali Ahmad - 22.04.2019 18:48

how can we find the size of a dynamically allocated array?

Ответить
play store
play store - 30.03.2019 17:06

that was awesome . I got the formula that I was seeking for. thank you very much for sharing this

Ответить
Jerry Lee Melton
Jerry Lee Melton - 06.10.2018 20:38

Thank you so much! I come from a Java background and this was giving me so much trouble in C++.

Ответить
Shekhar Gupta
Shekhar Gupta - 14.09.2018 09:32

But if I pass this array as a parameter to some function, then how to calculate its length ?

Ответить
nupur choudhary
nupur choudhary - 26.07.2018 15:31

very good

Ответить
K-Choi
K-Choi - 12.07.2018 17:18

how about when I pass the array to a function and get the sizeof inside that function, how do I handle such thing that it won't decay, assuming that the parameter only accepts the array?

Ответить
DarknessGu1deMe
DarknessGu1deMe - 10.07.2018 10:41

I see 2 problems with this:
1. what if a is of length 0, won't a[0] seg fault?
2. placing the macro in for loop conditional would make the evaluation at every iteration. (better to do it only once)

Ответить
Joaquim Jesus
Joaquim Jesus - 03.02.2018 17:45

i'm sorry, but these formula works with structures too?

Ответить
Andrew Manuel
Andrew Manuel - 25.01.2018 21:33

Hi, A bit confused on how your compiler is giving you 48 as sizeof(a); on my pc using the same code i am getting it straight answer e.g 10. Note: ignore my question i was actually using an unsigned char a[] instead of int a[].

Ответить
AT ATA021
AT ATA021 - 16.12.2017 22:44

what is meaning of
s1=sizeof(*arr); ?

Ответить
Deepa S
Deepa S - 14.09.2017 16:44

how to find sum of the array elements, if the number of array elements are given at the run time

Ответить
Ronald Crabtree
Ronald Crabtree - 28.06.2017 09:49

Thank you!

Ответить
Saroj Pradhan
Saroj Pradhan - 11.06.2017 10:57

Thank you! The instruction is very clear!

Ответить
Just like the movies
Just like the movies - 26.03.2017 05:24

Why don't you just say sizeof array divide size of element?

Ответить
Alexander Kermani
Alexander Kermani - 15.02.2017 00:18

So concise and informative. Really amazing job. I'm behind in my C++ class (because I went straight into second semester C++ class without the first semester one), and you, my friend, are going to get me through. Thank you for the vids!

Ответить
fhgjfgjdghj
fhgjfgjdghj - 06.10.2016 06:10

what is "stdafx.h"

Error 1 error C1083: Cannot open include file: 'stdafx.h': No such file or directory

Ответить
Mike Newman
Mike Newman - 16.08.2016 18:56

Thanks for this video, just ran into this particular problem not too long ago lol started C++ a week ago, you're a life savor! SUB!!!

Ответить
Daniel Valandra
Daniel Valandra - 30.07.2016 21:12

Mo you'er the man, not only are you a great teacher you are good at what you do; thank you!

Ответить
infinitytomorrow
infinitytomorrow - 07.04.2016 06:46

But what if I don't know how many elements are going to be in the array?

Ответить