How did you call the swap function when it was named foo ?
@ianneill9188 Жыл бұрын
Thank you... Adding this to my "watch again" list.
@ProfessorHankStalica Жыл бұрын
Glad you found it helpful!
@emreibrahim8504 Жыл бұрын
This guy is underrated i love your content!
@ProfessorHankStalica Жыл бұрын
Thank you for the kind words!
@W2CH1 Жыл бұрын
I needed a review on this thank you so much!
@ProfessorHankStalica Жыл бұрын
Glad it was helpful!
@jawwad4020Ай бұрын
@13:38 , line 23; Sir you are using std::swap() instead of the foo() that you defined above. Amazing video nonetheless, thanks a billion- I feel so much better about C++!
@leowatote22557 ай бұрын
I have been struggling with the content that you mentioned in this video before. Thanks a lot.
@ProfessorHankStalica7 ай бұрын
Happy to help!
@cornondanob67227 ай бұрын
thank you so much, this cleared up so many things
@ProfessorHankStalica7 ай бұрын
Glad it helped!
@Byynx Жыл бұрын
Great explanation. Congrats!!! To be clear when we create a pointer parameter "foo(int * a)" the compiler will create a new pointer variable that points to the the same place of what we pass is pointing too right?
@ProfessorHankStalica Жыл бұрын
A pointer is just a variable that holds a memory address. So, when you have a pointer parameter, all you are doing is creating a variable that holds a memory address, but it's scope is the function and it can be assigned a value by passing the function an argument rather than using an assignment statement. So, all you are doing (if you use pass-by-copy) is copying the contents of one variable to another, just like you would with any other type of variable. Example: void foo(int* a); . . . foo(b); Is similar to: a = b; The contents of the b pointer (which is a memory address) gets copied into a. That's all. Then the function can use the contents of a (the memory address copied from b) for whatever it needs to do.
@joey6047 Жыл бұрын
I love you
@ProfessorHankStalica Жыл бұрын
I love me too!
@errik9610 ай бұрын
@@ProfessorHankStalica
@faizaniftikhar10 ай бұрын
& and * together was fun :)
@ProfessorHankStalica10 ай бұрын
It FREAKS people out when they see it. It's like... int* x ..... no problem. Pointer. int& x ...... no problem. Reference. int*& x .... AAAAAAAAAAAAAAHHHHHHHHHHHHHHHHHHHHH WHHHAAATTTT IIIISSSS IIITTT!!!!!!?!!!!!!?????? NOOOOOOOOOOOOOOO! (It's a pointer reference)
@Cuteartandcraft-n1x5 ай бұрын
#include using namespace std; void random(int*&c,int*&d) { int p=7,q=8; c=&p; d=&q; } int main() { int a=2,b=3; int *c=&a,*d=&b; random(c,d); cout
@ProfessorHankStalica3 ай бұрын
You assigned invalid memory locations to your parameters. p and q are local inside the function and go out of scope, but you assigned their addresses to c and d. Your pointers were pointing to invalid memory locations after the call to random, so there's no way to know what values will be there with 100% certainty. Use dynamic memory allocation and it'll work. Assign memory addresses to parameters c and d for dynamic memory.