Hello, and welcome back. Another challenge for you.
Again, it's going to be on pointers. What I want to try to help you learn in this challenge
is the concept of pass by reference.
So even though c is doing everything passed by value,
it's actually making a copy of an address when you use pointers,
so mimics pass by reference.
And the big advantage of pass by reference is that when you change
a pointer's value or variable inside of a function,
a function, you're going to see the change reflected outside the function.
So we don't have to use global variables as much
and it's a big advantage to be able to pass in data
to a function as a pointer that mimics pass by reference.
So in this challenge you're going to write a program that tests your understanding of pass by reference
and how to use pointers to do this.
I want you to write a function that squares a number by itself.
The implementation of the function is going to be quite simple.
It's just going to square the number that you pass in.
So the function should define as a parameter in int pointer.
In your function declaration, it takes an int star which is a pointer.
And then inside your function implementation, all you're going to do
is you're going to need to de-reference the value of the pointer
and multiply it by itself.
You don't have to return any data from this function.
I just want to let you understand the concept of passing in
by reference or passing in a pointer.
The last thing that this program should do is it should print out
the value of the variable, the value of the pointer that you pass to the function.
So you don't even need to create a pointer to pass in.
You can use a regular perimeter data type an integer float.
It's just when you pass that integer float in,
it has to be the address because the function for square only accepts a pointer.
But again, what you're going to notice here is that the value
or the variable outside the function, the one that's being passed in
to the function is going to change
because you're using the address,
and this is going to mimic pass by reference. So good luck on this.
It's pretty straightforward.
Again, going to get you familiar with pointer syntax
as well as this concept of pass by reference. Thank you.