Hello and welcome to javadpoint and today the topic of discussion is C output based
question on pointers. So we will discuss various questions on pointers. So let's start with
the first question of pointer and the question is here you have given a main and one function
is called and you have to predict what will be the output of this following code either
A, B, C or D. So let's start with the solution of this question. Whenever you have been asked
to solve such type of question always try to make boxes for every variable. So first
of all we will start from main. So we have a variable A. So what we did we made a box
one with name A, one with name B. Let address of A be 100, let address of B be 200. So value
of A is 5 so I will put 5. Value of B is 6 so I will put 6. We have a pointer variable
and you know what is pointer? Pointer hold address. So P is the pointer variable which
hold the address of A. So let's again make a box because it's a variable it will also
have a memory it will also have a box so fine. So P name of this box is P let address of
this box be 300 and in P what you are putting in what in P in pointer P what you are putting
address of A. So what is address of A 100. So what you are putting inside is 100 fine
So you are putting inside P is what 100 fine. Now what happens? You again created a double
pointer. What is double pointer? Double pointer will hold the address of single pointer. So
let the name of this be Q and make it sure let address of this be 400 and this Q will
hold address of single pointer. Why? Because this is double pointer fine. So let's start
Now what happens? What am I doing is that pointer P is equal to 20. So let's start with
pointer P is equal to 20 means what is P? What is there in P? 100. So I will write 100
and after that pointer. So what is pointer 100? Value. So I will go to the 100 and after
putting pointer I will move inside. So pointer gives value at that address. So fine I will
move inside fine and what I am doing? I am changing its value from 5 to 20. So what will
happen this 5 value will get changed to 20. So finally what will happen? This will get
updated to 20. Fine hope you understood. Now let's move ahead. Q. Q is holding address
of P which is absolutely right because Q is a double pointer and double pointer will
hold the address of single pointer which is exactly right. So Q is having address of P
What is the address of P? 300. So Q will have 300. Fine. Ok now this line is completed
Fine again what I am doing is I am calling a function f with value a and address of b
So what is the current value of a? 20. So I will write 20 here and what is address of
b? 200. So I will write 200. The moment I call this function it will go to its body
So again what will happen? Again will create a variable. Fine why? Because these variables
are different from these variables. Even though two can have same name. Here we have P but
these two can have same name but they are exactly different. A two family can have same
name. A two family can have James as their son. Fine but this James is different from
this James. So let's start. What I did when on calling this function what will happen
The value of a will be passed to x and the value of 200 will be passed to P. So what
will happen? Two boxes will be created one with x one with P. Let the address, address
will be different. Let the address of x will be is 500 and let the address of this P is
600. So what I am doing is passing x with value 20. So 20 will come here. Fine. At passing
200 to value of P 200 will come here. Fine. Now what will happen? What am I doing is pointer
P. So write pointer P. What is there in P? Which P? This P. What is there in P 200? So
write 200. Pointer 200 means I will go to 200 address. I will move inside and what I
am doing is that I am see from this place I am jumping directly to this place because
pointer gives the value. Pointer access the addresses. So I came here to address 200 and
while moving inside what I am doing is I am changing value to x. So what is the current
value of x 20. So this value will be updated to 20. So what will happen? 20 will come here
Fine. Hope you understood now. Now what am I doing is I am changing x to 10. What will
happen? x will change to 10. But this will hardly make a difference. Now the body, the
task of this body, the task of this definition is complete. Now I will come to this line
This task is complete. I will come to this line. Pointer Q. What is Q? This is Q. So
write pointer Q. Let me rub all this now. What is Q? 300. So pointer Q is 300 values
So I will move inside. Fine. I am changing it address of B. What is address of B? 200
So I will make it 200. Fine. So I will make it 200. Hope you understood now. Now what
I am doing is pointer P. What is P? What is P? Write pointer P. What is P? 200. Now
P is 200. Pointer 200 means I will move inside this and changing this value from 20 to 30
So this value will become 30. Fine. And at last what am I doing is printing value of
A and B. What is the current value of A? 20. And what is the current value of B? Is 30
So answer will be B. That is 20 and 30. And yes exactly the answer is 20 and 30. So hope
you understood what this pointer was all about. In next upcoming session we will discuss
more question on pointer. Till then thank you so much for watching. Please like, subscribe
and share the channel. Please. Thank you. Thank you so much. Thank you very much