Difference between arrays and pointers in C

preview_player
Показать описание
int[] and int*... what is the difference actually? That's what we're trying to clarify in this video.
Рекомендации по теме
Комментарии
Автор

How can you have so little views, this content is the best I have found so far!

Miguel-mvyc
Автор

Hands down the best programming YouTube channel. I learnt a lot more than the Indian dudes that can't explain what an unsigned integer is.

imperatusmauser
Автор

I think of an array as a constant pointer, you can not assign a different address to arr, but you can use it to loop through the array i.e. * (arr+3) say to access its members. A pointer is more versatile as you can assign different addresses to it to point to different arrays and you can index through an array by using *(p++). int a[] ={1, 2, 3}, b[3] and trying to assign b=a I get caught with that sometimes. have to use memcpy to do that : )

noweare
Автор

thank you for this series of c programming, very helpful and very easy explained with correct type of examples.. realy thx man

sonyiq
Автор

Your content is gold. And your voice is pleasant to listen to while learning.

bestieboots
Автор

great explanation👏🔥, thanks for the video

talalquleh
Автор

Thanks, this cleared up a lot of confusion i had :)

diskoboi
Автор

Thanks for this!! it was really insightful.. keep it up!

iamqaasim
Автор

This is wonderful. Thanks for making these. I was also looking for tutorials on linker script, you know of any good resources on that?

pitankar
Автор

Thank you so much. That was one of my open question..

navidnouri
Автор

So when you use malloc and after that your int *p will be equal with the address of the first 4 bytes( first int variable) aka p[0] so it's actually the same case like of an usually array? What I mean the whole block of memory you allocated it will have as his address, the address of p[0] ?

edward
Автор

you explain things to clearly. thank you !

missrudy
Автор

What about when you need to dynamically allocate memory to a size not a constant (3 in your example). For instance, user inputs int sizeOfArray, but
Int * arrp = malloc(sizeOfArray * (sizeof(int)) doesn't compile

StealOfApproval
Автор

Question, what's the difference between passing ([][]) as a parameter instead of (**) for matrixes, for example.
int foo(a[]);
int foo(*a);
with one I need to use as a good practice?
do i need to always write foo ([]) if the passing parameter is a static allocated array?

itsmespiazzy
Автор

Why while intialization of a char array pointer memory allocated automaticly, but with int arrays we must allocate it manually

pawsdev
Автор

Thank you. I wondered why *array++ is invalid code. It kinda makes sense now why.

Immerz
Автор




This is a fantastic video, thank you for exploring this topic!


I was just wondering if you might consider making a video in the future as a sort of addendum which covers this same concept, but also with the subtleties that come with strings? There are so many ways to declare strings in C. For example:


char* readOnlyMemoryString = "spaghetti";
char arrayDeclarationOnly[];

char* dynamicString = malloc...;
char sugarString[] = "test123";


I got bitten by the first line at work recently because I did not realize that strings declared that way are placed in an area of memory that is neither in the stack nor the heap! I am finding string parsing to be very difficult. If you have already made a video on this topic, please disregard my comment! I am still making my way through your videos.

ed.peguillan.
Автор

why does char *name = "Bob" work but
char **names = {"Bob", "Bill", "Steve"} doesn't?

wrosen
Автор

Why is p[0]=1 ? it shouldn't be *p[0]=1 since
you are assigning a value and not an address?!

edward
Автор

So there is no difference at all, they differ only with math of navigation, in loop with pointer you use pointer increment p + n, and if you use square bracket you just increment number in square brackets [i+n], i saw only this. The a both limited in stage of init, array[] limited with number in [], pointer array is limited with malloc, so no difference if you use [3] or malloc size int*3 in final.
Yes, you can save memory in initialization, but who cares this in our days

pawsdev
join shbcf.ru