C++ POINTERS (2020) - What is a void pointer? (for beginners) PROGRAMMING TUTORIAL

preview_player
Показать описание
Void pointer in C++ is a general-purpose pointer, which means a special pointer that can point to object of any type. It is a typeless pointer also known as generic pointer.
But void pointers have certain limitations as well. They cannot be dereferenced directly. In this video, I'm explaining how void pointers are used in C++ on a simple, beginner-friendly example.

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️

Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇

Follow me on other platforms:
Рекомендации по теме
Комментарии
Автор

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
Experience the power of practical learning, gain career-ready skills, and start building real applications!
This is a step-by-step course designed to take you from beginner to expert in no time!
💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
Use it quickly, because it will be available for a limited time.

CodeBeauty
Автор

I am now a university freshman from China majoying in Network Security. I started to learn C++ when I was in high school but gave up due to its complex concepts. Now that we have to learn C++ in my major, I turned to this video to help. Your explaination is really clear and the words in this video is amazingly understandable for a Chinese whose mother tongue is not English. Really thanks you a lot and wish your channel will become better.

remysalone
Автор

Thank you much, Saldina!!! I used to be a wizard in C++ (back in the 1990's ..) ... havent used it for 30 years and you are the best "refresher" I've seen! A pleasure to follow you: charming, whitty, clear .. well done!

francescofaccodelagarda
Автор

Hey guys! I have a tip, instead of passing a type parameter and checking for different possibilities with a switch statement, you can use a C++ "template", they allow you to pass type arguments to functions!

template <typename T> // `T` will be the data type
void print(void *ptr)
{
cout << *((T *)ptr) << "\n"; just use `T*` to cast the pointer with the data type passed in!
}
Now, when calling the function, you can do something like this:

int main() {
int x = 20;
char grade = 'A';
print<int>(&x);
print<char>(&grade);
}

and like that you can pass any datatype within the angle brackets

hussainaqeel
Автор

I am from Ethiopia .
I am second year Hawassa university student .I woud like to say, thank you for your great helping for us.I get great knowledge from you

Apost
Автор

hey code beauty
your tutorials are so understandable
so please can you bring about competitive programming course

roninhacked
Автор

Why haven't I seen this channel sooner. Your tutorials are so helpful thank you!!!!

justbake
Автор

i assume this code is only theoretical, and in production you would use function overloading?
void print(int* val) {
cout << val << endl;
}

void print(char* val) {
cout << val << endl;
}

stefanfrei
Автор

We can simply use the keyword auto to print a pointer of any type, like:
#include <iostream>

void printPtr(auto* ptr)
{
std::cout << *ptr << std::endl;
}

int main(void)
{
int number = 5;
char letter = 'a';

print(&number);
print(&letter);

return 0;
}

TehCruiser
Автор

Thank you so much, you've taken away a lot of my confusion about pointers.

WolfsdenxD
Автор

Struct and void pointers are powerfull!

dealvin
Автор

Hi,
I learned a lot about C++... thanks!
But i don't get something, how can everything I learned be useful, could you make some mini-projects about real world applications in the most realistic way possible (So that I get the idea about what is it to work like a C++ programmer)

RustyRustacean
Автор

You are very good at teaching . Thanks a lot

alexanderriverasandoval
Автор

You can use template<typename T> after that create a function to hold every data type.

hama_kurdish
Автор

i do appreciate your work for making clear and understandable videos about pointers

ramazanhusaini
Автор

Thank you! It's easy to understand. Can you also make tutorial for different programming languages as well like Java, Python, Javascript, etc. ?

sousavann
Автор

Have watched a couple of the pointers videos now - great content!

JazzInATinCan
Автор

I just realized that you don't even need a switch statement to determine the datatype of the passed pointer. Just declare a template above the function: template <typename T>, and use whatever datatype passed with the function as the pointer to cast as: func<int>(&anInteger), then inside the function: cout << *((T*)ptr) << endl;

neck-o
Автор

Thank you so much for this amazing series of pointers.

mongalmoy_karmakar
Автор

Thanks that cleared up all of my questions on void pointers 🎉👍

jason_skillman