@@PortfolioCourses I really hope you do!! You explain things so clearly. I hope you make some tutorials about multithreading and reference counting 🤯 in the future as well!
I'm a web developer, but I'm interested in the C and C++ programming languages because most of the time if you want to learn a programming language, it's better to know the C programming language.
I think learning a lower level language like C can have benefits to all programmers, by learning how things work at a lower level and by learning a new way of thinking and how to solve problems. :-)
Hi. Something has been mind boggling me for a few days and I thought of you. I'm developing a C dll where a few functions receive structs by reference(pointer). Let's say I want to bind the passed struct object to the DLL (that is have a pointer in the DLL references the address of the passed struct instance) so that changes made in either DLL or client program take immediate effect. Many sources I read have shown examples of DLL functions accepting arguments by pointer { of the form bind(struct val*) }. Recently through trial-and error I realised that I can actually make the DLL function accept by reference - to my surprise, however now my question is, if DLL function accepts by pointer, how do you get the address from it, to point to it's own pointer (bind), and also if passed by reference, what is the procedure for doing the same? I hope I'm making sense. Also, if I pass a pointer (the actual integer/long value, how can I convert it to an actual pointer then deference it? I know I have asked a lot, but you have way more knowledge and understand than I do, and was hoping you could help me get some clarity. Thanks in advance.
I think I understand passing by value and passing by reference, but I have one question (so actually, maby I don't understand it fully haha): In 2:48, when You used function using pass by reference, the "&" symbol and then x, means that we are giving the function exact address in memory where that variable "lives" and then we are operating on her etc. And my actual question is about calling this function. Shouldn't we first create pointer to the "a" variable, and then pass that pointer to the function? I mean, I see it's working when we just provide "a" variable, but I'm mot really sure why.
Great question! 🙂 So "reference variables" and "pass-by-reference" is a different concept than pointers, even though they work somewhat similarly and use the same & symbol (which makes things confusing!). The &x does not mean we are giving the function the memory address, all it means is that the parameter is a "reference variable". And a reference variable basically becomes "another label for the variable it is set to". This video on reference variables might be helpful for you: th-cam.com/video/e3DN1RaYVYQ/w-d-xo.html.
@@PortfolioCourses ooooh, then that makes sense (the "&" symbol) why I confused these both concepts, I haven't watched that video yet, I'm watching all your C++ videos in chronological order. Gonna watch that right now! Thank you very much for your answer! 😀
When you spoke of shadow copies in passing non referenced variable objects. There exists another way. I do it by placing my counts and temporary buffers as variables in the header files above all of my data types and above all the functions to both access and change them without reference. It is far more easier for the compiler to reference them as global-like and do so without the confusion. A class with a counter placed above it can still access and change that global variable because doing it your way is also defining a reference, however its being done after compile time and is way more costly. The only time I ever use a reference's is when passing an array, a vector, a map, a struct array or a class container as an array. Then it becomes valuable in programming. int bag_cnt = 0; // OUR COUNTER. class Bagger { public: int bid; // WHERE WE STORE THE INCREMENTED COUNTS. int bdata; void assign_data(int dat) { bid = bag_cnt; bdata = dat; bag_cnt++ // WE INCREMENT IT HERE. }; }; int main () { Bagger b[200]; // we assign the class as a data type(w/it is one) with an array count of 200 b[bag_cnt].assign_data(44); // 0 b[bag_cnt].assign_data(93); // 1 b[bag_cnt].assign_data(23); // 2 }
Thank you sir for the most clearest and understandable explanation.
This was very easy to understand, much appreciated.
You're welcome Mike! :-)
I couldn't find a C++ course on your website. I hope you plan to make one! Your C++ tutorials are the absolute best.
I don’t have a full C++ for beginners course yet, but I’m really hoping to make one this year Thea! :-)
@@PortfolioCourses I really hope you do!! You explain things so clearly. I hope you make some tutorials about multithreading and reference counting 🤯 in the future as well!
Cool, thanks for the ideas! :-)
Clear and smooth explanation...!!!
Thank you Pasindu! :-)
I'm a web developer, but I'm interested in the C and C++ programming languages because most of the time if you want to learn a programming language, it's better to know the C programming language.
I think learning a lower level language like C can have benefits to all programmers, by learning how things work at a lower level and by learning a new way of thinking and how to solve problems. :-)
@Aboubakr Hollanda We've all got our favourites - I definitely love C++. :-)
Thank you this helped me fix my code for an assignment.
You're welcome Amber! 🙂
Hi. Something has been mind boggling me for a few days and I thought of you. I'm developing a C dll where a few functions receive structs by reference(pointer). Let's say I want to bind the passed struct object to the DLL (that is have a pointer in the DLL references the address of the passed struct instance) so that changes made in either DLL or client program take immediate effect. Many sources I read have shown examples of DLL functions accepting arguments by pointer { of the form bind(struct val*) }. Recently through trial-and error I realised that I can actually make the DLL function accept by reference - to my surprise, however now my question is, if DLL function accepts by pointer, how do you get the address from it, to point to it's own pointer (bind), and also if passed by reference, what is the procedure for doing the same? I hope I'm making sense. Also, if I pass a pointer (the actual integer/long value, how can I convert it to an actual pointer then deference it? I know I have asked a lot, but you have way more knowledge and understand than I do, and was hoping you could help me get some clarity. Thanks in advance.
Best explanation... thank you so much!!
You’re very welcome! :-)
I think I understand passing by value and passing by reference, but I have one question (so actually, maby I don't understand it fully haha):
In 2:48, when You used function using pass by reference, the "&" symbol and then x, means that we are giving the function exact address in memory where that variable "lives" and then we are operating on her etc. And my actual question is about calling this function. Shouldn't we first create pointer to the "a" variable, and then pass that pointer to the function? I mean, I see it's working when we just provide "a" variable, but I'm mot really sure why.
Or then maby I don't understand pointers fully haha
Great question! 🙂 So "reference variables" and "pass-by-reference" is a different concept than pointers, even though they work somewhat similarly and use the same & symbol (which makes things confusing!). The &x does not mean we are giving the function the memory address, all it means is that the parameter is a "reference variable". And a reference variable basically becomes "another label for the variable it is set to". This video on reference variables might be helpful for you: th-cam.com/video/e3DN1RaYVYQ/w-d-xo.html.
@@PortfolioCourses ooooh, then that makes sense (the "&" symbol) why I confused these both concepts, I haven't watched that video yet, I'm watching all your C++ videos in chronological order. Gonna watch that right now! Thank you very much for your answer! 😀
@@Klusio19 You're welcome! 🙂
finally jesus christ i get it.
Awesome, I'm happy to hear that Erica! 🥳
why dont you say ampersand
No real reason, I usually just call it the 'and' character because the & symbol standards for 'and'. And I guess it's shorter than ampersand. :-)
When you spoke of shadow copies in passing non referenced variable objects. There exists another way. I do it by placing my counts and temporary buffers as variables in the header files above all of my data types and above all the functions to both access and change them without reference.
It is far more easier for the compiler to reference them as global-like and do so without the confusion. A class with a counter placed above it can still access and change that global variable because doing it your way is also defining a reference, however its being done after compile time and is way more costly.
The only time I ever use a reference's is when passing an array, a vector, a map, a struct array or a class container as an array. Then it becomes valuable in programming.
int bag_cnt = 0; // OUR COUNTER.
class Bagger {
public:
int bid; // WHERE WE STORE THE INCREMENTED COUNTS.
int bdata;
void assign_data(int dat) {
bid = bag_cnt;
bdata = dat;
bag_cnt++ // WE INCREMENT IT HERE.
};
};
int main () {
Bagger b[200]; // we assign the class as a data type(w/it is one) with an array count of 200
b[bag_cnt].assign_data(44); // 0
b[bag_cnt].assign_data(93); // 1
b[bag_cnt].assign_data(23); // 2
}