Find The Length Of An Array Using sizeof() | C Programming Tutorial

Find The Length Of An Array Using sizeof() | C Programming Tutorial

Portfolio Courses

1 год назад

6,201 Просмотров

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


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

RishavDas
RishavDas - 31.07.2023 14:07

Thanks for this much of good content ❤

Ответить
Milton Tom
Milton Tom - 16.07.2023 05:58

what about 2d arrays?

Ответить
David Wu
David Wu - 04.07.2023 18:57

hello is it possible to do it inside of a function isntead of main ?

Ответить
Firas Faham فراس فحام
Firas Faham فراس فحام - 24.02.2023 07:32

Those various methods of passing length of arrays may all be used but with caution. A code having thousends of lines with error resulting from passing global as local value may give the developer nightmare trying to find the problem. One should pay attention to which method to use before deploying the code and implement new customer requirements in the code at later time. To be in the safe side I would define the size of the array along with the array before sending them for execution - every time, yes every time. For example: to command the wireless controller go into "COMMAND" mode I send the array (pointed to by a pointer *) making up the command bytes as bytes and send along with it the number of bytes and ask the responsible subroutine to process them, this gives me peace of mind. Now even if the customer request new changes later then the code can still work without any problem.

Ответить
Firas Faham فراس فحام
Firas Faham فراس فحام - 24.02.2023 07:08

Thank you Kevin for explaining the method to find size of array. Those C programming tips are very useful for embedded engineers like myself. I use them a lot in wireless and wired communications and user interface. Examples are communicating over the Bluetooth Low Energy (BLE), USART VCP port COMM, Electronic Control Panels, Robotics, Electronic displays and the like.

Ответить
悟空
悟空 - 07.02.2023 17:30

What is difference between size of an array and length of an array?

Ответить
Genevieve Kuzak
Genevieve Kuzak - 05.02.2023 08:04

This is one of the best coding videos I have ever watched

Ответить
Nub
Nub - 26.01.2023 13:51

That's an amazing video! Can you also make a video about a tictactoe game so I can finally understand how to build it :D

Ответить
HistoryImperfect
HistoryImperfect - 24.01.2023 23:38

I have a question.
Is it possible we allow user to enter the number of elements in a array
And program tells how many numbers user has entered ?
If possible then how? Please let me know.
I don't want to initialise the array , just want to take user input and print how many elements user entered .

Ответить
Aliyu Ibrahim
Aliyu Ibrahim - 25.11.2022 15:10

I can understand the concepts of programming in a class but I find it difficult to solve programming problems in a test or exam. Can you tell me why pls?and how can i solve the problems

Ответить
Aliyu Ibrahim
Aliyu Ibrahim - 24.11.2022 19:00

Each integer is 4bytes so 4x9 =36
​and 36 /4=9 right?

Ответить
Mauricio Yepez
Mauricio Yepez - 04.10.2022 03:39

the videos you make are so great and well explained sir , can you tell me which IDE are you using ?

Ответить
Nameless
Nameless - 29.09.2022 01:07

Thanks! Very Helpful

Ответить
Gurram Jayanth Reddy
Gurram Jayanth Reddy - 19.09.2022 11:54

Jefferson Sales done a few but not there yet

Ответить
Mnogojazyk
Mnogojazyk - 19.09.2022 02:24

Drat. Just when I thought there was a generic length(array) function to be had.

I am beginning to understand the limits of C, and I suppose this is one. That's okey. Nothing is perfect and everything has limits, and that includes computer programming languages.

Ответить
Lemmen Min
Lemmen Min - 18.09.2022 10:10

компилятор ругается на:
- void print_size(int* array) // warning: ‘sizeof’ on array function parameter ‘array’ will return size of ‘int *’ [-Wsizeof-array-argument]
- printf("sizeof(array): %ld\n", sizeof(array)); // warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]

Ответить