i am new to c and i know so much more python than c and i have to change a code from c to python, in the code to change i found this sentence:
p->arity = std::stoi(x, nullptr, 10);
i think for sake of simplicity we can use
p->arity = x; /* or some whit pointers im really noob on c but i think this is not importan */
in python does this means something like
p[arity] = x
or similar? or what? im a little lost whit all these new(for me) concepts like pointers and memory stuff but now whit -> operator
thanks in advance
CodePudding user response:
What I understand about the arrow operator from this post:
An Arrow operator in C/C allows to access elements in Structures and Unions. It is used with a pointer variable pointing to a structure or union.
Since Python doesn't deal with pointers, this is not directly comparable.
However, you can think of its usage as similar to the dot operator in Python.
class Random:
arity = 0
p = Random()
p.arity = x
CodePudding user response:
To access a member b in object a in C , the syntax is a.b
If c is a pointer to a instead of being a itself, then the syntax is c->a, equivalent to (*a).b
There are no pointers to objects in python so it would just likely be a.b
