In the screenshot it said x = *(++p) and iirc that is not the same as saying x = *(p++) or x = *(p += 1)
As in my example using ++p will return the new value after increment and p++ or p+=1 will return the value before the increment happens, and then increment the variable.
Or at least that is how I remember it working based on other languages.
I’m not sure what the * does, but I’m assuming it might be a pointer reference? I’ve never really learned how to code in c or c++ specifically. Though in other languages ( like PHP which is based on C ) there is a distinct difference between ++p and (p++ or p+= 1)
The last two behave the same. Though it has been years since I did a lot of coding. Which is why I asked.
I’ll install the latest PHP runtime tonight and give it a try xD
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
Posts must be relevant to programming, programmers, or computer science.
No NSFW content.
Jokes must be in good taste. No hate speech, bigotry, etc.
In C an assignment is an expression where the value is the new value of what was being assigned to.
In
a = b = 1
, both a and b will be 1.is the same as
, so ++p.
What I meant was:
In the screenshot it said
x = *(++p)
and iirc that is not the same as sayingx = *(p++)
orx = *(p += 1)
As in my example using ++p will return the new value after increment and p++ or p+=1 will return the value before the increment happens, and then increment the variable.
Or at least that is how I remember it working based on other languages.
I’m not sure what the * does, but I’m assuming it might be a pointer reference? I’ve never really learned how to code in c or c++ specifically. Though in other languages ( like PHP which is based on C ) there is a distinct difference between
++p
and (p++
orp+= 1
)The last two behave the same. Though it has been years since I did a lot of coding. Which is why I asked.
I’ll install the latest PHP runtime tonight and give it a try xD