I used to learn C and it got me back into wanting to re-learn all of the stuff I forgot. I think I have many "learn how to code in C" books lying around but I ended up stopping right about the part where it got into pointers. lol
@beepbeepgamer1305 imo c is actually the easiest language there is,but because it's so simple,writing anything more complicated than a text manipulation program is a pain because the language almost doesn't do anything for you
This is AWESOME. Very concise, excellent video. Well organized and jam packed with golden nuggets of interesting and relevant information. Keep up the great work!
1/2 Some key notes (not detailed and please correct my understanding where necessary): The main function is BOOM the big bang of the program where the code starts executing. This function sets off a chain of calls and returns from other functions. Nice diagram at 16:24 Naive change_value program (code at 23:02) -nb is an int variable set to 42. the nb variable is passed to the change_value function. Within the change_value function, nb is set to 1337. Now in the main function, nb is printed. What will the value of nb be? - The answer is nb will still have the value of 42. Why? This is because the variable nb is passed by value and not by reference. Basically a copy of the variable is passed to the change_value function rather than the memory address where the variable is stored. This means that change_value changes the value of a copy of nb to 1337 rather than the original nb variable. change_value program with pointers (code at 32:45) -So how would you change the original nb variable? -The answer is to pass a direct reference to the nb variable address AKA a pointer! -The code is changed such that change_value's parameter is a pointer (designated with asterisk (*) before variable name), the variable name is changed to foobar -*foobar is assigned the value of 1337 (The variable stored at the foobar pointer is assigned 1337) (foobar refers to the pointer that stores the address while *foobar refers to the variable stored at this address; referring to the variable stored at the address is called dereferencing) -Instead of creating an nb pointer in the main function the nb address can be passed directly as &nb -Now nb is successfully changed to 1337! We are dealing with the same nb variable stored in the same memory location rather than a copy of the nb variable! Classic Swap (code at 33:40) -a is an int variable assigned 42. b is an int variable assigned 1337. swap is a function that will switch these values using pointers. First, the addresses of a and b are passed to swap as parameters. -In the swap function, a is referred as n and b is referred as n1 (based on order when swap is called). -To swap the values, the int variable tmp is created to temporarily store n's value. n is then assigned n1s value. Finally, n1 is assigned n's original value. -Line 7 n is dereferenced, Line 8 n and n1 are dereferenced, Line 9n1 is dereferenced. Dereferencing simply means dealing with variables rather than the memory locations where variables are stored Why declaration and dereference have the same syntax? (34:05) -Worth watching this section, it is concise The main benefit of passing by reference is that you don't need to make a copy and therefore you save memory especially if you are passing something large like a large array Pointers have the same size for different data types, an analogy for this is that the empire state building address and a small restaurant's address are the same size, even though the size of the buildings are different If pointers are the same size, why do pointer types have to be specified? (pointer type = type of variable achieved by dereferencing pointer) Basically, different different data types are stored differently in a way that impacts pointer functionality. chars take up 1 byte, ints take up 4 bytes. (One memory address correlates to one byte) One example of how functionality is changed is pointer arithmetic: if pc is a char pointer (chars are 1 byte, a memory address holds 1 byte), and pc refers to the memory address 0x7ffeea5f930, pc + 1 would refer to 0x7ffeea5f931, pc + 2 would refer to 0x7ffeea5f932 if ptr is an int pointer (ints are 4 bytes, a memory address holds 1 byte), and ptr refers to the memory address 0x7ffeea5f930, pc + 1 would refer to 0x7ffeea5f934, ptr + 2 would refer to 0x7ffeea5f938 Pointers can be type casted (the pointer type is changed) line 13 in code at (50:57) which changes how the compiler interprets the variable stored in the pointer. Basically the pointer can act like the variable it is associated with is of a different type, while the actual variable is unchanged. I know this is confusing, please call me out if I am wrong about anything. As stem cells can become any cell type, or actors can be assigned any role, void pointers can later be assigned a data type.
At 31:25 you say everything works thanks to the power of pointers, but in the slide, the initial value is the same as the one you are changing it to ... I mean, it works like you say, but the initial value is identical to the changed value not sure why you changed it from 42 on the previous slide ... don't forget to get your slides reviewed
All the Code used and few notes here: medium.com/@jalal92/just-dereference-the-link-for-the-code-in-the-video-cdfc0c2d9547 I learnt myself a lot with freeCodeCamp and now, crazy enough, i produce myself tutorials! I will always be a promoter of this amazing project, empowering people for free all over the world. A particular mention to Beau that allowed me to be part of this, such a gentleman! ❤
Thanks for the video! Funny that in the compiler I have, gcc that came in my ubuntu distro, the example at around 59 minutes leads to a segmentation error, it does not print the int 42. Printing the address I see it is (nil), so it seems that when the stackframe for foo goes away the pointer is nil. I am not sure though if this happens because the compiler assigns nil to any function that tries to return an address to a local variable or else?
Video by itself is great, but there's one issue. That constant squelching is quite irritating. It's a habit you can unlearn, and it will improve your speech a lot.
when we just nibble at food when we arent that hungry.. thats called nibble and when we really feel hungry we bite the food .. thats what hes trying to say.. nibble and bite (byte) is sort of related to food analogy, i hope you understand what im trying to say :)
Line 3 is called a “prototype.” Notice that when used in main(), change_value isn’t defined until line 14. This would cause the compiler to reject the code. So using a prototype allows programmers to define the function before main() in order to avoid this error. Note that prototypes require the “;” whereas creating the function does not.
Not to be contrary, but pointers and absolute beginners is going to lead to overwriting all manner of memory. I know, I taught new employees to code in C. But you gotta start somewhere. Or skip and do Rust.
@@sarahyukino7213 Rust kind of has pointers but they are safe. In fact, Rust is so well designed that programs often work properly the first time you get them to compile, logic issues notwithstanding. Getting your code to compile can be mind bending though. I 100% think learning C pointers is time well spent. With function pointers and varargs, you can build polymorphic objects, and simulate an OO language. It's how C++ originally worked, it was compiled down to C (very interesting) code. Fun stuff.
@@marbasfpv4639 you got to thank God for the blessings he gave you like the ability to understand a complex subject such as pointers. my comment was to mark that i have already watched this so i dont forget and watch it again in the future.
I’m at 30 mins so far. So basically we just have to use the & sign when we pass variables in as arguments, and in our functions we use * to declare a pointer and deref inside the function. This way we can actually change the value of our original variable. Is that right?
As a computer science engineer I can see how understanding pointers pavement you to understand the underneath meaning of variables, arrays and complex structures. That's something that we all are forgetting with 'modern' languages.
I loved it! I sat down and typed the whole thing and every exercise and this helped a lot. The explanations and examples are really good, I learned a lot even if I thought I was not a total beginner. :)
Todavía no he visto el video pero en las explicaciones de pasar arrays a las funciones te ha faltado el caso del array de más de una dimensión, que en este caso sí hay que pasarle todas las dimensiones menso la primera a fin de que cuándo se haga uso del array dentro de la función éste sepa dónde buscar el dato. Por ejemplo: void (int my_array[][2], sizeof_t size) { ... }
Dear friend, you are totally right. The thing is that i thought about super beginners in this video-course. I rarely use 2D matrixes in real life, furthermore i don't wanna scare too much with too many details. This concept i'd say is for more advanced users. Here i just want to bring someone from 0 to 1 with pointers.
As someone who learned pointers at university, I found the video really useful, especially the introduction about computer memory. In my opinion, it's not really dedicated to "Absolute Beginners". Thanks for your efforts.
I guess you already found the answer, however I try to explain for myself: any pointer as well as any variable has an address in memory cell, the value in the memory cell can be changed... adding word const we deny changing value. So const pointer that link to address can't be changed, you can't assign pointer a new address. (pointer on const value is the different thing - and this means, that with pointer you can't change value by address)
Again thanks for the video. By the end there is this example using vmmap, I understand vmmap is only for mac. Is there a similar tool I can use on a Ubuntu machine?
I just started learning C/C++ and this gets dropped, definitely you guys are amazing, thank you for the course! This is really helpful
I used to learn C and it got me back into wanting to re-learn all of the stuff I forgot. I think I have many "learn how to code in C" books lying around but I ended up stopping right about the part where it got into pointers. lol
@@UToobUsername01 you dont work with C anymore?
are you still learning c? I just started learning c since there's an paper for c in my clg. C is tough ngl, how is it going on for you?
@beepbeepgamer1305 imo c is actually the easiest language there is,but because it's so simple,writing anything more complicated than a text manipulation program is a pain because the language almost doesn't do anything for you
This is AWESOME. Very concise, excellent video. Well organized and jam packed with golden nuggets of interesting and relevant information. Keep up the great work!
1/2
Some key notes (not detailed and please correct my understanding where necessary):
The main function is BOOM the big bang of the program where the code starts executing. This function sets off a chain of calls and returns from other functions. Nice diagram at 16:24
Naive change_value program (code at 23:02)
-nb is an int variable set to 42. the nb variable is passed to the change_value function. Within the change_value function, nb is set to 1337. Now in the main function, nb is printed. What will the value of nb be?
- The answer is nb will still have the value of 42. Why? This is because the variable nb is passed by value and not by reference. Basically a copy of the variable is passed to the change_value function rather than the memory address where the variable is stored. This means that change_value changes the value of a copy of nb to 1337 rather than the original nb variable.
change_value program with pointers (code at 32:45)
-So how would you change the original nb variable?
-The answer is to pass a direct reference to the nb variable address AKA a pointer!
-The code is changed such that change_value's parameter is a pointer (designated with asterisk (*) before variable name), the variable name is changed to foobar
-*foobar is assigned the value of 1337 (The variable stored at the foobar pointer is assigned 1337) (foobar refers to the pointer that stores the address while *foobar refers to the variable stored at this address; referring to the variable stored at the address is called dereferencing)
-Instead of creating an nb pointer in the main function the nb address can be passed directly as &nb
-Now nb is successfully changed to 1337! We are dealing with the same nb variable stored in the same memory location rather than a copy of the nb variable!
Classic Swap (code at 33:40)
-a is an int variable assigned 42. b is an int variable assigned 1337. swap is a function that will switch these values using pointers. First, the addresses of a and b are passed to swap as parameters.
-In the swap function, a is referred as n and b is referred as n1 (based on order when swap is called).
-To swap the values, the int variable tmp is created to temporarily store n's value. n is then assigned n1s value. Finally, n1 is assigned n's original value.
-Line 7 n is dereferenced, Line 8 n and n1 are dereferenced, Line 9n1 is dereferenced. Dereferencing simply means dealing with variables rather than the memory locations where variables are stored
Why declaration and dereference have the same syntax? (34:05)
-Worth watching this section, it is concise
The main benefit of passing by reference is that you don't need to make a copy and therefore you save memory especially if you are passing something large like a large array
Pointers have the same size for different data types, an analogy for this is that the empire state building address and a small restaurant's address are the same size, even though the size of the buildings are different
If pointers are the same size, why do pointer types have to be specified? (pointer type = type of variable achieved by dereferencing pointer)
Basically, different different data types are stored differently in a way that impacts pointer functionality. chars take up 1 byte, ints take up 4 bytes. (One memory address correlates to one byte)
One example of how functionality is changed is pointer arithmetic:
if pc is a char pointer (chars are 1 byte, a memory address holds 1 byte), and pc refers to the memory address 0x7ffeea5f930, pc + 1 would refer to 0x7ffeea5f931, pc + 2 would refer to 0x7ffeea5f932
if ptr is an int pointer (ints are 4 bytes, a memory address holds 1 byte), and ptr refers to the memory address 0x7ffeea5f930, pc + 1 would refer to 0x7ffeea5f934, ptr + 2 would refer to 0x7ffeea5f938
Pointers can be type casted (the pointer type is changed) line 13 in code at (50:57) which changes how the compiler interprets the variable stored in the pointer. Basically the pointer can act like the variable it is associated with is of a different type, while the actual variable is unchanged. I know this is confusing, please call me out if I am wrong about anything.
As stem cells can become any cell type, or actors can be assigned any role, void pointers can later be assigned a data type.
This is just the best course about pointers that I found online! 😀
I don’t understand how you guys always know what I’m Googling.
Brooooooooo.... It's wild..
They're in your walls
Hooray! Thanks for lession.
The very topic why I left c .now I am gonna try again ❤
"C and assembly are great starting points in the world of programming."
Best of luck! You got this!
This help students alot because pointers is difficult for students in programming
Someone needs to show this to CrowdStrike Developers.
You could enable close captions.
Saved the video for first year at university
At 31:25 you say everything works thanks to the power of pointers, but in the slide, the initial value is the same as the one you are changing it to ... I mean, it works like you say, but the initial value is identical to the changed value not sure why you changed it from 42 on the previous slide ... don't forget to get your slides reviewed
All the Code used and few notes here:
medium.com/@jalal92/just-dereference-the-link-for-the-code-in-the-video-cdfc0c2d9547
I learnt myself a lot with freeCodeCamp and now, crazy enough, i produce myself tutorials!
I will always be a promoter of this amazing project, empowering people for free all over the world.
A particular mention to Beau that allowed me to be part of this, such a gentleman! ❤
It's rather useful to rewind the video if you do not understand. A random passerby
Wow awesome video. Thank you for your contribution.
C IS HIGHLY EFFICIENT!
Brilliant video. Also subbed and clicked the bell. Waiting for your next video.
We also need a handlebars(hbs) tutorial as it will be very helpful since there is no tutorial for hbs in YT.
i love C
one of the best videos so far.
감사합니다.
very good
Brilliant, very well explained. Thank you for sharing your insight.
One correction: MacOS is NO king!
Great tutorial
wow, it makes me understand things! Thank you!
why there is turing picture in the backgroud in ide ?
Am I the only one curious about his vim setup. please how did you do that ?
Thank you very much for this content!
Simply the best 👌
Thanks for the video! Funny that in the compiler I have, gcc that came in my ubuntu distro, the example at around 59 minutes leads to a segmentation error, it does not print the int 42. Printing the address I see it is (nil), so it seems that when the stackframe for foo goes away the pointer is nil. I am not sure though if this happens because the compiler assigns nil to any function that tries to return an address to a local variable or else?
Thank you, my friend =)
Your videos have helped me so much!
how his video helped you if you just watch less then 10 minutes? and the video uploaded before 11 minute?💩
@@haniissa1990 I didn't watch this one? I used his python playlist. Why are you so argumentative?
Thx ❤
Video by itself is great, but there's one issue. That constant squelching is quite irritating. It's a habit you can unlearn, and it will improve your speech a lot.
35:00
I don't understand the joke between bit nibble and byte. 7:10 can someone explain? I am not a native speaker. What is that mean '4 bits are enabled'
when we just nibble at food when we arent that hungry.. thats called nibble and when we really feel hungry we bite the food .. thats what hes trying to say.. nibble and bite (byte) is sort of related to food analogy, i hope you understand what im trying to say :)
Thanks for the video!
Can someone explain, at 32:47, why do we need line 3? The function change value is already present at line 14 onwards.
Line 3 is called a “prototype.”
Notice that when used in main(), change_value isn’t defined until line 14. This would cause the compiler to reject the code.
So using a prototype allows programmers to define the function before main() in order to avoid this error.
Note that prototypes require the “;” whereas creating the function does not.
who is the lecturer of this video??!
pointer for abs beginners, the first example is a triple pointer, not very clear sorry.
It was not?
Do you have a video with generic pointers and memory by increment, also data structures with generic pointers.
I know less about pointers now because of this video, very confusing.
Not to be contrary, but pointers and absolute beginners is going to lead to overwriting all manner of memory.
I know, I taught new employees to code in C.
But you gotta start somewhere. Or skip and do Rust.
Does Rust not have pointers? I thought references and dereferences was about pointers
@@sarahyukino7213 Rust kind of has pointers but they are safe. In fact, Rust is so well designed that programs often work properly the first time you get them to compile, logic issues notwithstanding.
Getting your code to compile can be mind bending though.
I 100% think learning C pointers is time well spent. With function pointers and varargs, you can build polymorphic objects, and simulate an OO language. It's how C++ originally worked, it was compiled down to C (very interesting) code. Fun stuff.
As a cs student who wants to learn more about the computer systems, do u recommend c or rust?
who is here from alx???
brooooo
@@clintonsibanda6852 lmaoo
❤
could you teach how you turn the gcc and ./a.out code into one function? You named it "r", how do I do that?
gcc example.c -o example && ./example
The -o part stipulates what you’ll name your program instead of the default ‘a.out’
38:31
13:32
I'm piscine 42 ecole this moment.
what does that 1337.42 mean :)
1337 is the belgian variant i think of the 42 school, free programing school, he probably got examples outta that
@@Tugahzyeah I know I study there
if you like live long then doesn't learn c :)
What the f#&k is he talking about 😢? It's supposed to be a teaching aid for beginners!
I hate emojis in this video. Please consider change that style, cause for me it was very disturbing to learn
11110
1+F+111
usless video. First learn english, we can learn pointers later
Terrible bait
C is a classic language never get old evergreen thank you once more FFC
FreeFodeCamp
@@SS-jq6mhlmao 💀
❤
I almost forgot C even had pointers 😂.
How did you not C dat?
😅😅😅😅😅😂
@@theencryptedpartition4633 was busy tangling with 🐍
How do you use C then?
Nobody pointed out the pointer to you?
تم بحمد الله، اللهم انفعنا بما علمتنا وزدنا علما.
Lol what does any of this have to do anything with some god??
@@marbasfpv4639 you got to thank God for the blessings he gave you like the ability to understand a complex subject such as pointers. my comment was to mark that i have already watched this so i dont forget and watch it again in the future.
@@marbasfpv4639 ولو كره الكافرون
I’m at 30 mins so far. So basically we just have to use the & sign when we pass variables in as arguments, and in our functions we use * to declare a pointer and deref inside the function. This way we can actually change the value of our original variable. Is that right?
As a computer science engineer I can see how understanding pointers pavement you to understand the underneath meaning of variables, arrays and complex structures. That's something that we all are forgetting with 'modern' languages.
I learned about 'pointers' with rust, don't know if it's the same thing with C
Interesting
Very true
This ma mannn right here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! thx a lot cuh ))))))))))
Long live C 🔥
I loved it! I sat down and typed the whole thing and every exercise and this helped a lot. The explanations and examples are really good, I learned a lot even if I thought I was not a total beginner. :)
Sadly watching this on a phone is basically impossible because of the images and color use. Guess it gottta be on a pc screen
The first 40 minutes was all it took for me to understand this concept of pointers clearly.
Great Tutorial!
The same. I understand this concept after watching the first 40 minutes of the video
Can someone please explain how he got 0100 at 1:08:45
I appreciate your work thank you so much for your video
thank for these pointers, Goodç7
O tema me interessa muito, mas o meu ingles é muito pobre - The topic interests me a lot, but my English is very poor
Todavía no he visto el video pero en las explicaciones de pasar arrays a las funciones te ha faltado el caso del array de más de una dimensión, que en este caso sí hay que pasarle todas las dimensiones menso la primera a fin de que cuándo se haga uso del array dentro de la función éste sepa dónde buscar el dato. Por ejemplo:
void (int my_array[][2], sizeof_t size) { ... }
Dear friend, you are totally right. The thing is that i thought about super beginners in this video-course. I rarely use 2D matrixes in real life, furthermore i don't wanna scare too much with too many details. This concept i'd say is for more advanced users. Here i just want to bring someone from 0 to 1 with pointers.
I just spent today reading chapter 5 of K & R's C programming and this video came 😂....such a weird coincidence
Best language book and it's not even close. Although Borland Turbo C Bible was useful.
Idk how you got through K&R that book is absolutely atrocious
Thank you.
Thanks guys will you arrange a session about crack games/softwares?
that course is something different and and an amazing course i hopefully could finish it as soon as possible and thanks freecodecamp
Does stack grow top to bottom or bottom to top ???? Chatgpt says that it grows from bottom to top .
Top to bottom for stacks , and bottom up for heaps
Over 2 hours on just pointers? Now I know why C programmers hate them so much.
I never hated them, but on the Unix side we had core dumps and you could rebuild the program at point of crash.
Thank you for the lesson, but the fonts and shapes used in the education materials are very poor.
I loved this! I finally understood the pointer concept. Thank you for this.
This tutorial just dropped at the right time.
I wish the author uses emglish phrasing im a more standardized way. It would be more clear what he wanted to explain.
Good tutorial but why you don't activate subtitle cc
So anyway this is the best C Tutorial on UA-cam…. Well Done!!! 👏🏽 👏🏽 👏🏽
Miller Kenneth Taylor Karen Thompson Ruth
i knew pretty much all of this but watched it anyways because why tf not
i have finished c exam yesterday and saw this video today :(
Lopez Carol Davis James Thompson Sharon
As someone who learned pointers at university, I found the video really useful, especially the introduction about computer memory.
In my opinion, it's not really dedicated to "Absolute Beginners".
Thanks for your efforts.
Can someone explain to me what is const pointers? Is very common to see functions with const pointers as input
Can we have some examples of these functions, please?
@@eduardof.vicentini9225 void func (const int* p){
// do stuff;
}
Guys, GPT is out!
I guess you already found the answer, however I try to explain for myself: any pointer as well as any variable has an address in memory cell, the value in the memory cell can be changed... adding word const we deny changing value. So const pointer that link to address can't be changed, you can't assign pointer a new address. (pointer on const value is the different thing - and this means, that with pointer you can't change value by address)
I want to learn software engineering on UA-cam, can I get recommendations and scheme for this?
Informative ❤❤❤
what is the compiler name and version does he use?
Lee Donna Thomas Maria Johnson Frank
sorry after the first 40 minutes, it is difficult for a beginner to understand anything.
Learn c language first. (Not only basic but also intermediate)
Then you'll understand.
@@smallSphere69 it says for absolute beginners on the title
@@petrosstyle2981 title is kinda misleading
This is very helpful thanks.
2 hours of lectures about pointers? Most videos are like 5 mins and I feel that they do not help at all this is great!
Yes 🎉 1st
Grazie
Again thanks for the video. By the end there is this example using vmmap, I understand vmmap is only for mac. Is there a similar tool I can use on a Ubuntu machine?
vim
data strcture in c please