No video

Void Pointers | C Programming Tutorial

  Рет қаралды 9,486

Portfolio Courses

Portfolio Courses

Жыл бұрын

A tutorial about void pointers and how to use them in C, where void pointers are 'generic pointers' without an associated data type. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

Пікірлер: 52
@StreuB1
@StreuB1 Жыл бұрын
You honestly have a gift for teaching this stuff. Typecasting is an obtuse topic at times and a typecast pointer is very obtuse. I've never really understood them and how they are used, until now.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thanks so much for the kind feedback Brian, and I'm glad the video was able to help clear that up for you! :-)
@naboulsikhalid7763
@naboulsikhalid7763 8 ай бұрын
when it's great, it is always great and always will be. The pointers were my roadblock until now, but things have become smoother and I can follow without fear. Thanks, Kevin, for the great effort which is priceless.
@charliesta.abc123
@charliesta.abc123 Жыл бұрын
Another complex topic explained simply. Thank you for all your teachings. Your teaching style is top tier
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're very welcome Siya, I'm glad you enjoy the videos! :-)
@Lichen1
@Lichen1 Жыл бұрын
holy crap not to be weird but im high and i was literally just wondering about void pointers and your video just came out so this is great!! thank you!! also your tutorials are so helpful. i greatly value the knowledge you impart.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Hahaha I had a weird feeling that "today, I should make a video on void pointers", maybe it was destiny! :-) You're welcome Anthony, I'm really glad to hear you enjoy the tutorials.
@arthur_p_dent4282
@arthur_p_dent4282 Жыл бұрын
😂 cheers
@justcurious1940
@justcurious1940 10 ай бұрын
@@PortfolioCourses "Destiny is all " : Uhtred of Bebbanburg.
@tracetv8115
@tracetv8115 11 ай бұрын
I found ur videos about c and u are an absolute genius in explaining things! Thank u so much for ur content!
@LeFede
@LeFede 7 ай бұрын
the GOAT in c
@justcurious1940
@justcurious1940 10 ай бұрын
Extensive explanation about this topic, Thanks Kevin.
@NikolaNevenov86
@NikolaNevenov86 Жыл бұрын
To me the whole thing with pointers devolves to simply memory access. A type pointer will read the memory address depending on the type(int* will read 4 bytes and will decode the bits as int). A void pointer is a typeless pointer, it holds a memory address but does not know what is there. I think the fact that all pointers(regardless of type) are of the same size was a big eye opener to me. That being said, when we are moving the void pointer via pointer arithmetic, then the movement acts like that of the char* where each move is done in 1 byte * n . A type pointer will move depending on it's type, like a int* will move 4 bytes. Thus recently I wondered if there is any benefit to a void pointer since it acts like a char*. Of course one of the benefits is that it's typeless and thus can be a pointer to any type. Making it more universal.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I agree that the size of all pointers being the same is a big eye opener for people as to 'what pointers are really doing'. :-)
@grimvian
@grimvian Жыл бұрын
Again, great video! I see the void pointer as a multi-type pointer with some restrictions. When I 'malloc' memory, I use the data type(s) to format the memory to the desired type in pedagogical way.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thanks! :-) I always think of void pointers as something like "polymorphic behaviour" in C programming.
@grimvian
@grimvian Жыл бұрын
@@PortfolioCourses I think it's because you are an IT-professor and I'm absolutely not... :o) Your pedagical skills are also great and not many are capable of combining these two very diffrent tasks in a good way. I'm actually have dyslectic issues, but your very clear voice makes the learning much easier. Sorry for my English.
@MultiScott1000
@MultiScott1000 Ай бұрын
nice explanation. thanks.
@parosdelos6914
@parosdelos6914 10 ай бұрын
Would you mind making a playlist on all the pointer videos you've done so I can follow them chronologically?
@goktugparlak1618
@goktugparlak1618 10 ай бұрын
Thank you so much for great explanation
@fifaham
@fifaham Жыл бұрын
Nice explanation, thank you Kevin.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I’m glad you enjoyed it Firas, and you’re welcome, I hope you are well! :-)
@Joao-oo8yj
@Joao-oo8yj Ай бұрын
I did understand pretty well this thing about pointers... but I was wondering why the heck the function `qsort` you show in the video takes a pointer parameter which type is void*? `qsort` is gonna iterate over each contiguos address of the array, but how will it do that if the pointer type is void* which doesn't accept arithmetic operations?
@PortfolioCourses
@PortfolioCourses Ай бұрын
You provide a function to qsort, and that function does the comparisons, typically using a typecast to convert from void * to something you can do comparisons with.
@eugenebespalov9471
@eugenebespalov9471 Жыл бұрын
If I saw *((char *)p) before, I'd definitely freak out! Thanks for your videos, this is no longer the case.
@grimvian
@grimvian Жыл бұрын
Me too and the difference between making a pointer and get the value from a pointer.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome, I'm glad the video helped with that! :-)
@wlcrutch
@wlcrutch 7 ай бұрын
Is it fair to say that, when you “p is pointing to a memory address if any type of data” for void *p that we could also say: “p is pointing to a memory address that can hold a data type of any size”? If I am thinking of a memory address (size depending on the hardware if course) then it is a series of bits that are either high or low…and the data type tells us (in addition to helping write correct programs) how many bits we can store there? or am I taking my microcontroller class (in assembly) too seriously? 😅
@sonvallano897
@sonvallano897 9 ай бұрын
Great video
@PortfolioCourses
@PortfolioCourses 9 ай бұрын
Thank you, I’m glad you enjoyed it! :-)
@arthur_p_dent4282
@arthur_p_dent4282 Жыл бұрын
Great stuff as always.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad you enjoyed it Arthur! :-)
@otaxhu
@otaxhu 6 ай бұрын
please could you do an example using _Generic keyword??
@yoruichi5802
@yoruichi5802 Жыл бұрын
Saw a video of something similiar to manipulate floats, i think it was indirection or something… like this: float a; uint32_t temp = *(uint32_t*)&a; then manipulate the bits on the float and cast (float*) on it again
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Cool! :-)
@justcurious1940
@justcurious1940 10 ай бұрын
But it has nothing to do with void !!! 🙃
@starc0w
@starc0w Жыл бұрын
I was curious if you will mention that pointer arithmetic on void pointers is illegal according to ISO C. You did mention it! Excellent tutorial! Thank you so much! If we don't need a cast after malloc in C, can we use the following syntax to keep the instruction more generic? int* ptr = malloc(n * sizeof(*ptr)); (No need to adjust the right side of the assignment if the pointer type of "ptr" should change). Is this legal according to ISO C? Would you do it the same way professor? Thank you very much!
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! I'm not sure if that's legal according to ISO C, though it seems to compile OK in gcc at least and I don't see why it would be illegal. I don't know if I would do it that way or not, I think if I was changing the type of 'ptr' anyways, then it might not be a big deal to change the sizeof() as well. On the other hand it's nice to only have to change one thing, so I think it may depend on the situation.
@starc0w
@starc0w Жыл бұрын
@@PortfolioCourses Ok! Thank you very much!👍
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@starc0w
@starc0w Жыл бұрын
@@PortfolioCourses I found it in the Standard (the latest one). Page 82 (Not the PDF page, but the page number that the document itself lists). 6. 5. 3. 4 The sizeof and alignof operators Paragraph 6. I would like to post the link, but then KZbin deletes my post. There is also an example on "cppreference" in the chapter malloc.
@justcurious1940
@justcurious1940 10 ай бұрын
​@@starc0w Yes I have seen examples like this on "cppreference" and according to ChatGPT the sizeof operator does not need to dereference ptr to determine its size, it only needs its type.
@ozkanakbas4805
@ozkanakbas4805 Жыл бұрын
hi can you make a video about serial communication in c?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I've never done serial communication before Ozkan, but thank you for the idea you never know maybe one day I can cover it, I'm looking into it now and it's interesting. :-)
@ozkanakbas4805
@ozkanakbas4805 Жыл бұрын
@@PortfolioCourses 😁
@kunnudev7250
@kunnudev7250 Жыл бұрын
awesome bro plz cont.....
@yoruichi5802
@yoruichi5802 Жыл бұрын
Nice
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad you liked it! :-)
@starc0w
@starc0w Жыл бұрын
Dear Professor Since you usually replied soon, I suspect you missed my message below. :-)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I haven’t had time yet to answer questions. :-)
@aleXelaMec
@aleXelaMec Жыл бұрын
So why not using only void pointers!? Any disadvantages in size of such pointer?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Great question! :-) When we use a double pointer, and do pointer arithmetic, the compiler will adjust the pointer arithmetic to make it work for the size of a double (and this goes for any other type). With void pointers, this won't work. Typed pointers also allow the compiler to give us errors/warnings if we try to use them in ways that are unexpected.
Designated Initializers For Arrays | C Programming Tutorial
8:58
Portfolio Courses
Рет қаралды 1,9 М.
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 59 М.
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
Survive 100 Days In Nuclear Bunker, Win $500,000
32:21
MrBeast
Рет қаралды 153 МЛН
Little brothers couldn't stay calm when they noticed a bin lorry #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 17 МЛН
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 351 М.
Introduction to Pointers | C Programming Tutorial
24:42
Portfolio Courses
Рет қаралды 108 М.
The What, How, and Why of Void Pointers in C and C++?
13:12
Jacob Sorber
Рет қаралды 52 М.
why do header files even exist?
10:53
Low Level Learning
Рет қаралды 389 М.
Dynamic Memory Allocation | C Programming Tutorial
31:51
Portfolio Courses
Рет қаралды 81 М.
struct Basics | C Programming Tutorial
24:44
Portfolio Courses
Рет қаралды 135 М.
Function-like Macros | C Programming Tutorial
24:12
Portfolio Courses
Рет қаралды 19 М.
Weak Pointers in C++ (std::weak_ptr)
17:25
The Cherno
Рет қаралды 46 М.
why are switch statements so HECKIN fast?
11:03
Low Level Learning
Рет қаралды 400 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45