« first day (2342 days earlier)      last day (578 days later) » 

04:28
@Dante Hi :-)
It was years ago we chatted here wasn't it? Four years?
So you must be pretty close to finishing college now?
04:57
@JohnRennie Hi! Good Morning
Hi :-)
Free? Want to pester you with some doubts :D
Yes I'm free :-)
#include<cstdio>
struct book {
    char name[10];
    int price;
};
int main(){
    book bk;
    bk.name[0]='h';
    bk.name[1]='a';
    bk.name[2]='r';
    bk.name[3]='r';
    bk.name[4]='y';
    bk.price=500;
    printf("the price of the book is %d\n the name of the book is %s",bk.price,bk.name);
}
@JohnRennie Is there a shortcut way to insert 'harry'?
strncpy(bk.name, "harry", sizeof(bk.name)-1);
05:07
Like can't I insert an array of character,string etc (IK array wont work as it is second class )
In C there are a number of functions starting with str that manipulate strings.
@JohnRennie Can you explain MOP-> in memory address term? Basically, it assigns the information of the pointer to an object?
Suppose you modified your code to be:
#include<cstdio>
struct book {
    char name[10];
    int price;
};
int main(){
    book bk;
    book* pbook = &bk;
}
To set the price using pbook you'd have to write:
(*pbook).price = 500;
Because *pbook is the same as bk so this is equivalent to:
bk.price = 500;
OK so far?
05:22
But it's a hassle to have to write (*pbook) every time so C++ provides a shortcut:
pbook->price = 500;
is the same as:
(*pbook).price = 500;
It's just a neater way of writing the same thing.
Whenever you see:
foo->bar = whatever;
It means foo is a pointer to a struct or object.
So *foo is the struct or object.
This is very common in C++ as we are often working with pointers to objects.
In this following code, what is trooper1.insert_after(&trooper2) ? I have seen & only in finding the address
#include <cstdio>
struct Element
{
    Element *next{};
    void insert_after(Element *new_element)
    {
        new_element->next = next;
        next = new_element;
    }
    char prefix[2];
    short operating_number;
};
int main()
{
    Element trooper1, trooper2, trooper3;
    trooper1.prefix[0] = 'T';
    trooper1.prefix[1] = 'K';
    trooper1.operating_number = 421;
    trooper1.insert_after(&trooper2);
    trooper2.prefix[0] = 'F';
    trooper2.prefix[1] = 'N';
    trooper2.operating_number = 2187;
The declaration of insert_after is:
void insert_after(Element *new_element)
So as its argument it takes an Element* i.e. a pointer to Element. Yes?
05:34
But the type of trooper2 is Element so we cannot write:
trooper1.insert_after(trooper2);
because that would be passing an Element when the function expects a pointer to Element.
Yes?
But &Element is a pointer to Element. So the argument to the function has to be &trooper2
Writing:
trooper1.insert_after(&trooper2);
is effectively the same as:
Element* foo = &trooper2;
trooper1.insert_after(foo);
10 mins ago, by Wolgwang
In this following code, what is trooper1.insert_after(&trooper2) ? I have seen & only in finding the address
So in fact here & is indeed finding the address of trooper2.
I think I got this. I had seen a similar thing in another example where we were inserting an array as an argument(same parameter) .somefunc(array_name), here & was not required because of the array's similar characteristics with pointers(decay etc) (?)
@JohnRennie Ah!
Yes, if you write:
int foo[10];
the the type of foo is int* i.e. foo is a pointer to int.
So:
int foo[10];
foo[0] = 666;
printf("%d", *foo);
would print 666.
Yeah
05:43
Or more generally *(foo+i) is the same as foo[i]
This can be very useful when manipulating arrays, but it's easy to make mistakes programming arrays with pointers so care is needed!
@JohnRennie In that trooper code,`next` is a null pointer?
{
new_element->next = next;
next = new_element;
}
I have never seen "->(pointer)"
{
        new_element->next = next;
        next = new_element;
    }
Here are so many next. I am a bit confused.
Your definition of the Element struct is:
struct Element
{
    Element *next{}; // next has type "pointer to Element"
    void insert_after(Element *new_element)
    {
        new_element->next = next;
        next = new_element;
    }
    char prefix[2];
    short operating_number;
};
So the next member variable is of type Element*. Yes?
The function insert_after is defined inside the struct, and inside the struct next means (this struct).next
So:
new_element->next = next;
is doing:
new_element->next = this.next;
i.e. it's setting the next variable of the struct new_element equal to the next variable of the current struct.
Hmm. Pointers are confusing :/
05:57
It's simpler than you link.
The exercise is creating a linked list. Yes?
In a linked list each node contains a pointer to the next node in the list:
So for a list with three nodes, a, b and c we have:
a.next = &b
b.next = &c
c.next = NULL
The node with its next variable set to NULL is the last one in the list.
Does this make sense?
@JohnRennie Yes
Suppose you have list with one node a and you want to add a new node. You need to do something like:
Element* b = new Element;
a.next = b;
b.next = NULL;
And now you have a list with two nodes:
a.next = b;
b.next = NULL
Yes?
@JohnRennie Yes
06:07
Suppose we now want to insert a new node c in between a and b i.e. have our list look like:
a ⟶ c ⟶ b
Then we need to do:
Element* c = new Element:
c->next = a->next; // to make c.next = b
a->next = c; // so that a.next = c
This gives:
a.next = c
c.next = b
b.next = NULL
OK so far?
And this is what the insert_after() function is doing.
void insert_after(Element *new_element)
{
    new_element->next = next;
    next = new_element;
}
If you call:
Element* c = new Element; // c is  pointer to Element
a.insert_after(c);
Then it will do:
void insert_after(Element *new_element)
{
    new_element->next = next; // this sets c-> next to a-next
    next = new_element; // this sets a->next to c
}
Does this make sense?
Aha! I got it!
Thanks :D
Though I think it will take time to familiarise with this.
Pointers are confusing at first.
I learned them 40 years ago so they seem easy to me now :-)
 
6 hours later…
12:46
@JohnRennie Will you be around 9:00 PM IST ?
 
2 hours later…
14:20
@KavinIshwaran Yes
14:32
Ok :-)
14:56
@JohnRennie Are you free ?
I'm eating lunch. Ping me at 9 p.m.
15:21
Hello @JohnRennie sir
@KavinIshwaran Hi :-)
@PandaScientist Hi :-)
1
Q: Tension, Centripetal force and Simple-Pendulum

PandaScientist At position 3 We've to find tension in the string (ideal). The answer is: $$ T = mg\cos\theta $$ But my doubt is, how can Tension at 3 balance the radial component of gravity. If that were so the centripetal force should be zero but that's certainly not the case since the mass is exhibiting circ...

53 mins ago, by Kavin Ishwaran
user image
They are asking what could be the possible values of R1 and R2
Can we say the net radial force is centripetal force? @JohnRennie
+ I also have a few doubts in this question
15:31
@PandaScientist Kavin is first in the queue. Give me a few minutes to answer his question and I'll get back to you.
@JohnRennie ◉⁠‿⁠◉ okk sir
@JohnRennie at R value of 0, 1.5 A current flows, that means the middle joint must be shorting the two branch right ?
@KavinIshwaran The diagram shows the current for a range of values of R, but we are only interested in the two limits of R = 0, I = 1.5 and R = ∞, I = ⁴⁄₃
OK so far?
Yes
So at I = 4/3 the middle resistor is ineffective
Let's take R = 0 first: as you say that means we replace R by a short so we have R₁ and R₂ in parallel twice. Yes?
15:35
Yes
So 2R1R2/R1+R2 is Reff
So the total resistance is 2R₁R₂/(R₁ + R₂)
V/reff = 1.5
@KavinIshwaran Yes :-)
then verify with the options ?
@KavinIshwaran Well what we've got is the first of two simultaneous equations in R₁ and R₂.
2R₁R₂/(R₁ + R₂) = 10/1.5
Yes?
15:38
Yes
And we'll get the second equation from R = ∞, I = ⁴⁄₃
In this case we replace R by an open circuit, so now we have R₁ + R₂ in parallel with R₁ + R₂ making Reff = (R₁ + R₂)/2.
Yes?
So now we have a second equation:
(R₁ + R₂)/2 = 10/⁴⁄₃
Yes?
And we have two equations in two unknowns so we can solve for R₁ and R₂
We can go through this together if you want, or you can have a go on your own.
15:41
I will have a go :-)
OK. Do you want to go through the second question now?
24 mins ago, by Kavin Ishwaran
user image
@JohnRennie Yes
This is pretty straightforward. You start by finding the total resistance, and that will give you the total current. Yes?
I have no Idea what is an accumalator
accumulator just means battery
15:44
Oh
So it's just a 2V battery.
I think an accumulator is strictly speaking a rechargeable battery but for this question it's just a 2V battery.
Ok then :-)
Can you do the question now?
OK :-)
Can I answer @PandaScientist now?
15:47
@JohnRennie I am done :-) But will you be around here for a while ?
Only a short while longer so be quick :-)
@PandaScientist Usually in questions like this the centripetal force is small enough to be ignored. You are correct that strictly speaking we should include but often question just ignore it.
@PandaScientist Ah, wait.
The position 3 is the end of the swing i.e. when the bob is momentarily motionless before it starts to swing back towards the centre. That means v = 0 and hence ω = 0.
@JohnRennie yes, sorry for late reply
@JohnRennie yes?
The centripetal force is Fc = mrω² so that means at position 3 the centripetal force is momentarily zero.
Even if there is a tangential acceleration?
Yes. The bob is moving in an arc of a circle so the equations for circular motion apply i.e. v = rω and aᵣ = rω².
15:53
Last question, was I correct when I said " centripetal force is the net radial force if it is inwards"...?
The radial acceleration aᵣ depends on the tangential velocity not the tangential acceleration.
@PandaScientist Kind of ...
In this case the force towards the pivot comes from two sources:
1. the circular motion
2. gravity
At other positions(other than 3 and 1), Tension is greater than the radial component of gravity, right??
Strictly speaking centripetal force just means the net force towards the centre so it does mean the sum of 1 and 2.
But we tend to use centripetal force to mean just mrω² and not include forces due to other sources like gravity.
@JohnRennie aah, that should imply that centripetal force is just instantaneous tangential velocity dependent?
@JohnRennie ok sir
@PandaScientist Correct, the radial force would be mg cosθ + mrω²
@PandaScientist I think I would normally take centripetal force to mean just mrω² or equivalently mv²/r.
I guess read the question carefully to check how the question defines it.
16:00
@JohnRennie v in your expression stands for magnitude of instantaneous velocity, right?
Instantaneous tangential velocity.
Last request: can you pls specify the time slots when you're available here...?
UK time:
- from about 5 a.m. to 12:30 p.m.
- from about 5 p.m. to 6 p.m.
India is currently 4¹⁄₂ hours ahead of the UK.
Thanks a lot sir.
So from about 9:30 a.m. to 5 p.m. then 9:30 p.m. to 10:30 p.m. Indian time.
16:05
Ok sir
@JohnRennie Hi !
Are you free
Hi, yes I'm free :-)
16:29
@KavinIshwaran solved it yourself?
@JohnRennie Yeah I solved that already
By symmetry
Yes :-)
Have you got another question or is that it now?
I am looking for a question where I was stuck, But my documents Folder is flooded with questions, difficult to find a particular question :-)
I need to go now. If you find the question post it and I'll look at it tomorrow morning.
Ok then we will see it later :-)
16:33
Bye :-)
:-)
Ah ! found it !
A rod of length l has varying cross section as shown, the resistivity of the rod is $\rho$ resistance across the conductor is:
 
1 hour later…
17:57
@JohnRennie Glad you remember! I finished my college. Working as a software engineer now since 2 moths. How have you been sir?

« first day (2342 days earlier)      last day (578 days later) »