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

preview_player
Показать описание
In this video I will show you a technique to automatically get the size of an array in C/C++ using sizeof operator without having to hard-code the value

Thank you for your support!
Рекомендации по теме
Комментарии
Автор

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!

Alexanderkermani
Автор

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

danielvalandra
Автор

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

jerryleemelton
Автор

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!!!

mikenewman
Автор

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

playstore-hpvk
Автор

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

__hannibaalbarca__
Автор

Beautiful explanation. Thank you so much!

SideQuestingWithLorrie
Автор

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

JasonKT
Автор

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)

DarknessGudeMe
Автор

Thank you! The instruction is very clear!

SarozPradhan
Автор

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.

andrewpark
Автор

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.

manoharnookala
Автор

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

DansonPiano
Автор

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?

K-Choi
Автор

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

lotpot
Автор

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

aliahmad
Автор

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

ShekharGupta
Автор

what is "stdafx.h"

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

abcdefghijklmnopqrstuvwxy
Автор

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[].

mrmanuel
Автор

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

atata
visit shbcf.ru