Exellent pedagogical instructor - top class. I consider myself at medium level. I'm writing C code at regular basis, but Kris is closing the the little holes in my knowlegde here and there. Strange that Kris don't have more subscribers.
Interesting! I had learned C in school but I never imagined that arrays in C is so complex coz Java ran over this language in class. I'm a Java programmer for the last 17 years and python now and it's so common to work with these types that when you step back to C, man, I got confused LOL Back to basis
Great tutorials! But, I've got really stupid question: 33:00 - if we increment *words pointer it would have the same effect as incrementing **word_ptr, right? It does "switch" to the next address or will it become just garbage?
Wait a minute! What was sizeof words? 3? (around minute 30 ... you asked us and then never explicitly answered I don't think... typing it out in vim now!) EDIT: Oh geez... apparently the sizeof(words) is 24? How does that happen? sizeof(a) is 2, sizeof(b) is 4, and sizeof(c) is 5. 5 + 4 + 2 = 11 ... and then you + 1 and * 2 for some reason after that??? EDIT2: Ok I think I get it... Since a is essentially &a and &a is 8 characters long... 8 * 3 elements in words = 24 bytes in total correct? :S Great video by the way!
it gives the size of the type it has nothing to do with the value. int x = 20; sizeof(x) will return 4 bytes assuming int is 4 bytes. sizeof(int) is the exact same. if you have an array of 4 ints the size of the array would be 16 bytes. in the case of char it would just be 1 byte per element so the size of the array would also be the number of elements. remember it returns the size in bytes so if i have 4 integers in my integer array i can do sizeof(array) / sizeof(type) which will return the number of elements total. 16 / 4 = 4 integers.
The fact that you get 24 tells me that you have a 64 bit system, here is why: Words is an array of pointers to a char. That is 3 pointers in this case. Therefore the total size of words is the size of 3 pointers to chars. Because pointers are memory addresses, it doesn't actually matter what they point to when we evaluate their size - While the values stored at that address may have different size, it doesn't matter if I give you the memory address to a char, int, short, long etc., the address number itself (the hexadecimal) has the same size. For a 64 bit system, the addresses are 64 bit in length, which is 8 bytes. So 3 addresses is 3*8 = 24 bytes. If you compile that code on a 32 bit system, the length of words would be half that, because then addresses are only 4 bytes.
@@flyingmadpakke the type just tells you how many bytes taken up as well as the format. int and float assuming both 4 bytes take up the same memory but have different formats. a short assuming 2 bytes would be 2 memory addresses but the pointer is always to the base address which depends if the address mode is 32 bit or whatnot. 32 bits is 2^32 addresses or 8 hex digits. types have nothing to do with memory locations therefore pointers dont have types its just how should the data at that address should be interpreted and where does the next value start whether it be 2 or 4 bytes away or whatever. if you reinterpret data as a different type by casting to say char* it will only look at the first byte.
@@lilyscarlet2584 I agree with you. This is what I meant by saying it doesn't matter what type the pointer is pointing to because the pointer itself is ultimately a memory address, which is a number that is always the same size on your system, either 32 or 64 bits. For example, on my system I get sizeof(void*) = 8 and printing my addresses gives me 16 hex digits, because I have a 64 bit system. I actually don't know if some systems store more (or less) than 1 byte pr. address. As pointer increment has correlated 1:1 with byte size of types as far as I have seen, i.e. incrementing the pointer of an int increments the address by 4, this seems to be common, but maybe other memory implementations exists.
Best explanation of a pointer to a pointer. I finally understand what it means. Thank you Mr. Jordan!!
Exellent pedagogical instructor - top class. I consider myself at medium level. I'm writing C code at regular basis, but Kris is closing the the little holes in my knowlegde here and there.
Strange that Kris don't have more subscribers.
Interesting! I had learned C in school but I never imagined that arrays in C is so complex coz Java ran over this language in class.
I'm a Java programmer for the last 17 years and python now and it's so common to work with these types that when you step back to C, man, I got confused LOL Back to basis
You're doin' good job!
Great job explaning pointers 👍
This was so helpful and helped me complete a lab. Thanks.
such a good explanation, very thankful for u
Thank you boss!.
Great tutorials! But, I've got really stupid question: 33:00 - if we increment *words pointer it would have the same effect as incrementing **word_ptr, right? It does "switch" to the next address or will it become just garbage?
Wait a minute! What was sizeof words? 3? (around minute 30 ... you asked us and then never explicitly answered I don't think... typing it out in vim now!)
EDIT: Oh geez... apparently the sizeof(words) is 24? How does that happen? sizeof(a) is 2, sizeof(b) is 4, and sizeof(c) is 5.
5 + 4 + 2 = 11 ...
and then you + 1 and * 2 for some reason after that???
EDIT2: Ok I think I get it... Since a is essentially &a and &a is 8 characters long... 8 * 3 elements in words = 24 bytes in total correct?
:S
Great video by the way!
it gives the size of the type it has nothing to do with the value. int x = 20; sizeof(x) will return 4 bytes assuming int is 4 bytes. sizeof(int) is the exact same. if you have an array of 4 ints the size of the array would be 16 bytes. in the case of char it would just be 1 byte per element so the size of the array would also be the number of elements. remember it returns the size in bytes so if i have 4 integers in my integer array i can do sizeof(array) / sizeof(type) which will return the number of elements total. 16 / 4 = 4 integers.
The fact that you get 24 tells me that you have a 64 bit system, here is why:
Words is an array of pointers to a char. That is 3 pointers in this case. Therefore the total size of words is the size of 3 pointers to chars.
Because pointers are memory addresses, it doesn't actually matter what they point to when we evaluate their size - While the values stored at that address may have different size, it doesn't matter if I give you the memory address to a char, int, short, long etc., the address number itself (the hexadecimal) has the same size.
For a 64 bit system, the addresses are 64 bit in length, which is 8 bytes. So 3 addresses is 3*8 = 24 bytes.
If you compile that code on a 32 bit system, the length of words would be half that, because then addresses are only 4 bytes.
@@flyingmadpakke the type just tells you how many bytes taken up as well as the format. int and float assuming both 4 bytes take up the same memory but have different formats. a short assuming 2 bytes would be 2 memory addresses but the pointer is always to the base address which depends if the address mode is 32 bit or whatnot. 32 bits is 2^32 addresses or 8 hex digits. types have nothing to do with memory locations therefore pointers dont have types its just how should the data at that address should be interpreted and where does the next value start whether it be 2 or 4 bytes away or whatever. if you reinterpret data as a different type by casting to say char* it will only look at the first byte.
@@lilyscarlet2584 I agree with you. This is what I meant by saying it doesn't matter what type the pointer is pointing to because the pointer itself is ultimately a memory address, which is a number that is always the same size on your system, either 32 or 64 bits. For example, on my system I get sizeof(void*) = 8 and printing my addresses gives me 16 hex digits, because I have a 64 bit system.
I actually don't know if some systems store more (or less) than 1 byte pr. address. As pointer increment has correlated 1:1 with byte size of types as far as I have seen, i.e. incrementing the pointer of an int increments the address by 4, this seems to be common, but maybe other memory implementations exists.