On paper, they seem like a weird concept... void pointer... as in... pointer to nothing? No, that's not it. In this video we'll explain what a void pointer actually is and how it can be used.
Пікірлер: 37
@SafwanMashrafiSaraf-ll1wl19 күн бұрын
honestly the way u explain pointers is very fascinating and easy to remember keep it up brother 😁
@gauravchaudhari6182 жыл бұрын
finally programming tutorials thtat can be watched on smartphone
@draco5991rep5 жыл бұрын
Finally an accent which is understandable ^^' I really tried to follow all the indian dudes but sometimes I just wasn't sure I understand it correctly. They all made good videos (I think) but it was so hard to understand them, because they all try to beat eminem in saying the most english words in one minute xD
@warplanner88522 жыл бұрын
I find this young gentleman's accent (Russian?) very pleasant and his earnestness and energy in teaching most gratifying. While I understand the concept of void pointers, the only failing he had in this lesson was that the example wasn't exactly real world. Had it been so, then it would have been an excellent piece of instruction..
@shvideo12 жыл бұрын
Thank you for this great video! Really enjoyed your presentation. As a novice C programmer, here's one (brute-force way) to specify to what type to cast the void pointer inside the function: #include void printBytes(void*, int size); int main(int argc, char *argv[]) { int arr[] = { 16, 31, 32, 65 }; printBytes(arr, 4, sizeof(int)); } void printBytes(void *arr, int size, int typeSize) { for (int i = 0; i < size; i++) { switch (typeSize) { case 4: // Cast the void pointer to appropriate type then dereference it to get it's value. printf("%08x", ((int*)arr)[i]); break; default: printf("????"); break; } printf("|"); } } Outputs: 00000010|0000001f|00000020|00000041|
@CodeVault2 жыл бұрын
Very nice! Good job!
@adeled88334 жыл бұрын
My brain is like splash-splash after this video
@martingeorgiev999 Жыл бұрын
It's important to note that casting a pointer to a pointer of incompatible type is undefined behavior since it violates the C strict aliasing rule which is designed for code optimizations. You can however cast to and from void and char pointers and compatible pointer types. In particular 2:23 is erroneous (you can see that the compiler outputs a warning) but 8:04 technically isn't(the warning stays since the pointers are of different type but the code would always work fine and it isn't dangerous). GCC turns on this rule in -O2 and -O3 optimization levels with the -fstrict-aliasing flag.
@zuzukouzina-original5 ай бұрын
void pointers are also used for assigning callback functions. That’s what I used void pointers for.
@daniels48473 жыл бұрын
Finally I understand it! Thank You!
@JC-jw2kw3 жыл бұрын
Excellent video.
@reenko Жыл бұрын
Love your hacker style so interesting
@matteopisati99662 жыл бұрын
Well done !
@mercnem68553 жыл бұрын
When you go to Walmart to buy some socks and end up with an ironing board, 2x HDMI cables, Fruity Pebbles, and foot lotion.
@arpit55064 жыл бұрын
4:35 can cast it before dereferencing
@user-or7ji5hv8y5 жыл бұрын
Do you have a video where you discuss what hexadecimal is?
@CodeVault5 жыл бұрын
No. I will release a video on it next week. Thanks for the question!
@AlanBarrettVideos5 жыл бұрын
Man ascii
@MrDp9000 Жыл бұрын
But what if we cast the arr to lets say int or long int type? Then we dont need to put 4*sizeof() but only 4, right? Will it work?
@CodeVault Жыл бұрын
Yes, but you would still need to iterate each byte of each int individually
@jayaprakashms67692 жыл бұрын
How to calculate mean of all data type numbers using void pointer concept
@CodeVault2 жыл бұрын
You can't know the data type from just the void pointer. You'd have to have something else identifying the data type the void pointer points to
@xbz24 Жыл бұрын
I love you
@adeled88334 жыл бұрын
Stupid question: why print it in hexadecimal?
@CodeVault4 жыл бұрын
For this example, we could've printed it all in decimal. It just looks better that way (every byte is 2 hexadecimal digits) and memory is much easier to read in hexadecimal (generally) than in decimal.
@adeled88334 жыл бұрын
If we did it in just decimal(%02d), then it would all be the same, but the numbers would look normal ?
@adeled88334 жыл бұрын
Im just having a hard time turning each element of an integer array into a char, since the format they are stored in the memory is different for char and int
@CodeVault4 жыл бұрын
We'd probably need to use %03d since numbers can go up to 255. What code do you have so far regarding that conversion issue? Can you post it?
@adeled88334 жыл бұрын
CodeVault thank you for explaining! No, I don’t have one, I’m just trying to understand how the type change works
@gabehcuodsuoitneterp2032 жыл бұрын
char* arr -> char *arr
@CodeVault2 жыл бұрын
I prefer to put the type information (and other attributes) in one place and declare each variable on a separate line. But declaring it like that is fine as well