C Programming Tutorial 28, Pointers pt.4

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

Рекомендации по теме
Комментарии
Автор

Keep it up man, doing great so far....

TheDoppelganger
Автор

I do believe you are correct in that it only stores the first element (name=&name[0], *name=name[0]).

However array elements are stored in memory consecutively (I believe that is the correct word) meaning that element one is followed by element 2, etc. So having the pointer to the first element would allow you to increment the pointer by the size of the element (I believe chars are one byte or 8 bits) and get the next element.

Obviously I'm not iTzAdam5x, just someone trying to learn more.

FreeER
Автор

Thank you this cleared up a lot of problems :) hope to see more! ^^

ryuuxhana
Автор

I'm nominating you for hero of the universe.

WinterMute
Автор

I figured I could also easily see for myself and wrote and executed the program. As it turns out it does return "o" at index7. Also interesting to know, at index10 the first character of the email address is stored.

AYearOld
Автор

So the computer had allocated that 21st location for another purpose. So in your case the computer has used it to store e-mail information. It's like if you have 10 fingers and you say my 11th finger, that would just be the first finger of the next person.

I hope that makes sense.

amrouf
Автор

Just a question out of curiosity : if we use John D\0oe I assume the oe will still be saved so the saving structure then will be John D\0oe\0 is that correct ? thx

SuperSamsosa
Автор

Hello, I have a question - it's been bugging me for a while now. In this video you said that an array is the exact same thing as a pointer. So, *name = name[]. However, doesn't *name only store the address of the first element of the array? And not the entire array?

radicalone
Автор

Okay, this is not Adam, more like a fan of Adam... Anyway, if the name has lets say 10 elements, then there are 10 memory locations associated with this array. So if you print out the 10 memory of the array c1.name[9], that should print out the character in the 10 location. But, if you print out c1.name[20] i.e. the 21st element of the array, that 21st location isn't part of name; it's outside of name because the computer didn't allocate it for name.

amrouf
Автор

Hi Adam,
i have a doubt related to this video.
when i tried
printf("%c\n", c1.name[]);
with index value beyond that in c1.name, compiler would return an error but I got output with values from that in c1.email
please explain why is that happening as c1.name and c1.email are different arrays.

lawler
Автор

It's easy this way but this is a bad practice. If the user has to enter the name and email at run-time, your technique will not work. I think even the compiler will give an error. You have to allocate that memory first (dynamically (using: malloc) or statically (for example using a large enough string (to accommodate a possible big email address) like: char str[50];)).

mrjonsmith
Автор

assigning a pointer without any allocation a number of values wouldn't work
you would need to malloc and then copy

joaosidonio
Автор

@ Redjol Resulaj - go tutorial 23, 24.

ciprixenomorph
Автор

And if you read the 8th character at index7 you would get "o"? prinf("%c\n", c1.name[7] );

AYearOld
welcome to shbcf.ru