AnswerBun.com

In c, is there an equivalent of "+=" for "p = p->next"?

Stack Overflow Asked by Kai on December 19, 2020

I’m currently learning C and am now at the part of structs and lists.
I just wondered, if there ist something like "a = a+b" = "a += b" for this case.

2 Answers

No. You could use a macro, but i wouldn't.

Answered by 12431234123412341234123 on December 19, 2020

If you are using C++ then instead of the raw pointers you could define your own class of iterator for a list that internally contained the pointer p.

In this case you could substitute the expression

p = p->next;

for the expression

++it;

that under the hood will do p = p->next.

Something like

iterator & operator ++()
{
    iterator::p = iterator::p->next;
    return *this;
}

where the pointer p is a data member of the class iterator.

As for the compound assignment operator then there are no such operators like ->= or .=. So you can not overload them.

According to C and C++ Standards the assignment operator is one of

= *= /= %= += -= <<= >>= &= ^= |=

Answered by Vlad from Moscow on December 19, 2020

Add your own answers!

Related Questions

Flight destination check programm – C++

3  Asked on January 12, 2021 by mrfreeman16

   

How to execute (./myscript) inside awk or bash script?

3  Asked on January 12, 2021 by redouane-nouh

   

Disable nuxt link based on boolean

3  Asked on January 12, 2021 by samantha

     

Android Preventing Double Click On A Layout with handher

1  Asked on January 12, 2021 by user13380366

     

How to center align the label text inside the option tag?

1  Asked on January 11, 2021 by mr-spock

         

How can I read the CSS for mobile images

0  Asked on January 11, 2021 by power-rico

   

Deleting from array using unset creates values

2  Asked on January 11, 2021 by cameron

 

passport.socket.io cant fix no session found

2  Asked on January 11, 2021 by edi_hadzic

         

Output should look like a quotation

4  Asked on January 11, 2021 by maurya

   

Sorting DateTime column in ASP.NET MVC

2  Asked on January 11, 2021 by steven85791

     

Rounding does not match all expected results

1  Asked on January 11, 2021 by aa-44

   

Django tabular input form (user can key in data into table)

1  Asked on January 11, 2021 by eka-buyung-lienadi

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP