Passing Pointers to Functions -- C++ Pointers Tutorial [7]

  Рет қаралды 2,281

Professor Hank Stalica

Professor Hank Stalica

Күн бұрын

Пікірлер: 21
@TonyB-cy2qd
@TonyB-cy2qd 6 ай бұрын
How did you call the swap function when it was named foo ?
@ianneill9188
@ianneill9188 Жыл бұрын
Thank you... Adding this to my "watch again" list.
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Glad you found it helpful!
@emreibrahim8504
@emreibrahim8504 Жыл бұрын
This guy is underrated i love your content!
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Thank you for the kind words!
@W2CH1
@W2CH1 Жыл бұрын
I needed a review on this thank you so much!
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
Glad it was helpful!
@jawwad4020
@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++!
@leowatote2255
@leowatote2255 7 ай бұрын
I have been struggling with the content that you mentioned in this video before. Thanks a lot.
@ProfessorHankStalica
@ProfessorHankStalica 7 ай бұрын
Happy to help!
@cornondanob6722
@cornondanob6722 7 ай бұрын
thank you so much, this cleared up so many things
@ProfessorHankStalica
@ProfessorHankStalica 7 ай бұрын
Glad it helped!
@Byynx
@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
@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
@joey6047 Жыл бұрын
I love you
@ProfessorHankStalica
@ProfessorHankStalica Жыл бұрын
I love me too!
@errik96
@errik96 10 ай бұрын
@@ProfessorHankStalica
@faizaniftikhar
@faizaniftikhar 10 ай бұрын
& and * together was fun :)
@ProfessorHankStalica
@ProfessorHankStalica 10 ай бұрын
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-n1x
@Cuteartandcraft-n1x 5 ай бұрын
#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
@ProfessorHankStalica
@ProfessorHankStalica 3 ай бұрын
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.
Dynamic Memory Allocation -- C++ Pointers Tutorial [8]
18:25
Professor Hank Stalica
Рет қаралды 26 М.
Returning Pointers from Functions -- C++ Pointers Tutorial [9]
11:52
Professor Hank Stalica
Рет қаралды 4,5 М.
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 10 МЛН
Good teacher wows kids with practical examples #shorts
00:32
I migliori trucchetti di Fabiosa
Рет қаралды 13 МЛН
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 39 МЛН
1 сквиш тебе или 2 другому? 😌 #шортс #виола
00:36
30 Programming Truths I know at 30 that I Wish I Knew at 20
17:41
C++ Pass by Value, Reference, Pointer Explained
9:33
Caleb Curry
Рет қаралды 43 М.
Why are function pointers useful?
6:43
CodeVault
Рет қаралды 31 М.
Arrays are constant pointers -- C++ Pointers Tutorial [3]
11:36
Professor Hank Stalica
Рет қаралды 1,4 М.
you will never ask about pointers again after watching this video
8:03
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 317 М.
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 10 МЛН