Arrays, Pointers, and Why Arrays Start at Zero?

preview_player
Показать описание
---

***

Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.

About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.

More about me and what I do:



***

Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.

About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.

More about me and what I do:

To Support the Channel:
+ like, subscribe, spread the word

Want me to review your code?

You can also find more info about code reviews here.
Рекомендации по теме
Комментарии
Автор

I've been binge-watching your videos even though I know most of this stuff already. It's refreshing how you explain it in a way that's clear, concise, and strangely entertaining. Keep up the good work!

TheMentalGentelman
Автор

Thank god I found this video. Watched a few pointers videos and none of them explained it well enough. When hearing it compared to arrays, it just clicked, especially with the *(p+1...5) notation. Instant sub, thank you!

chillydill
Автор

That explosion at 4:23 gave a mini-heart attack lol

sathirasilva
Автор

Great stuff! It was an eye opener when I read Andersons "Advanced C". It made the whole shebang a lot clearer. Thanks for posting this!

HansBezemer
Автор

I've figured it out reading K&R. I'm happy to hear confirmation from you. Thanks.

LingvoScienceUSA
Автор

really love how you pointed this out very early. understanding this is the first important milestone in learning c

B-yi
Автор

Wow. I never knew why arrays started with 0. It makes a lot of sense now. Thank you kind sir for sharing this knowledge. Long live C and long live you!

natr
Автор

Man you are just diff from any creator out there
your teaching skills is so good. IDK much about arrays and pointers but you got me and now i understand everything.
Thanks for this Great series and Video

kenkaneshki
Автор

I tought I knew what pointers and arrays where, but I didn't know that they have so much in common. Thanks for your videos

Rodourmex
Автор

Excellent video! Many people have strong feelings for and against the C language!!

joshgibson
Автор

It was very useful ... thank you so much sir for the great video 😘😆

wirelesskiller
Автор

When declaring an array like usual as in int V[5]; then using the name of that array later like just V, then you are basically using a pointer which points to the first index of the array V[0]. I think that's the way the compiler looks at it and that's WHEN the compiler treats the array as a pointer and that's how we should organise that bit of info in our head.

Array is treated as an array if it is used the usual way by declaring or calling it with its index. And treated as a pointer if it is just called by its name without a specific index. That's when it is possible to just assign it to another pointer or a newly created one.

Correct me if I am wrong but this is the way I look at it to not get confused. It is all in the end just a design decision of the compiler and not a hardware thing.

Thanks for the info about why arrays start with zero, I didn't know that design decision was specifically meant for pointer arithmetic. I just thought it is okay to start from zero in counting...this video is not fro beginners though 😂

Sakuraigi
Автор

good vid. The music at 1:00 was a little overpowering of the vocals, just fyi.

JohnHollowell
Автор

4:09
when i access v[13] compiler lets me do it
i can even print it no error
but when i try v[2200]
same for p[ ]
my point is the size of array is 6
so 13 and 2200 both are not in this array
then why one works one not

if i am wrong plz correct me

this is the code :----
#include <stdio.h>
int v[6] = {1, 2, 3, 4, 5, 6};
int *p = v ;

int main() {

v[13] = 3334; // this one works
printf(" answer is %i ", v[13]);
// v[2240] = 8989 ;
// printf(" answer is %i ", v[2240]); //this one throws error

return 0 ;
}

bait-kxph
Автор

I'm just watching this series out of pure curiosity 😅
I've been jumping from one programming language to the other.
What I like more about c is that you have to specify the data type when declaring variables.
The other thing I noticed is that structs look like objects right?
Pointers I just don't understand. I wonder how much I can get done in c without using pointers.

jazzyniko
Автор

damn you really had me at that explosion! great video too.

rifatulkarim
Автор

While I understand this is for beginners, it might have been a missed opportunity to "point out" that offset notation can solve some problems.
eg: Processing a series of "triple values" (like 3 dimensions).
int dims[999], vols[333]; // Length, Width, Height values for 333 items...
for( int *p = dims, i = 0; p < dims + 999; p +=3, i++ )
vols[ i ] = p[ 0 ] * p[ 1 ] * p[ 2 ];

rustycherkas
Автор

Yeah, the 0th element of an array is 0 bytes from the beginning of the array, but it also starts at the first byte (1st), so starting at 1 would have made at least as much sense and made everything a lot easier in every language that copied C. Is there any practical advantage except that 1-10 has one more character than 0-9?

AGAU
Автор

If the founders had the foresight to make things easier for programmers they could have created a placeholder code in the 0 location, and let the first number be the first offset X/

elysewilliams
Автор

Can you do a video that explains what's happening with the portaudio library code examples. I emailed you about drivers but it may be helpful just to breakdown how callbacks usually work, and how the memory is being organized in the program.

williamraezer