Hello, and welcome back.
We have our first challenge for our section on pointers.
This is going to be a challenge that gets you acquainted with the pointer syntax.
Mainly you're going to create, initialize a pointer,
assign an address to a pointer and then display some of the pointers values.
So in this challenge, you're going to learn how to create initialize assign and access a pointer.
Creating the pointer is just declaring it.
Initializing it will be you initialize it to null because it's not going to point to anything,
and that's how you can do.
Assigning it, you'll assign it the address of another variable
and then accessing a pointer is using the indirection operator,
the dereference operator.
So write a program that creates an integer variable with a hard coded value.
That's pretty easy, we know how to do that.
The reason you have to create the integer first is because that's going to have a
memory location that you're pointing to.
And once you have that integer variable created,
you then want to create a pointer, initialize it to null
and then assign the address of the int to the pointer,
using the address of operator, pretty straightforward.
I want you to display as output the address of the pointer.
The address of the pointer is just when you declare the pointer,
the pointer has an address in memory.
You'll need to use the address of operator to display the address of the pointer itself.
Then i want you to display the value of the pointer
the value of the pointer is going to be another address, it's going to be the address of your integer variable
and then lastly i want you to display the value of what the pointer is pointing to.
The value of what the pointer is pointing to
you have to use the dereference operator, the indirection operator.
These are the three things that a pointer can be equal to.
You also have to understand what format specifier to use in each case.
Typically, you'll use a certain format specifier for addresses
and then you'll use a different format specifier for
whatever the pointer is pointing to.
This is a basic
assignment to get you familiar with the syntax of a pointer
and also understand the different values that a pointer can
store, again, mainly the address of the pointer itself,
the pointer's value which is an address to some other location,
and then the pointer pointers value of what's pointing to from that address which would be
the value using the indirection operator.
So good luck. I'll provide a solution to get you familiar with the simple syntax.
Hopefully, this won't take you too long.
But it's a good little exercise to help you become familiar with pointer syntax.
Thank you.