how to multiply with a dereference?

Write your question here.

*p is a deference.
**p is a pointer.
So if I want to multiply with a *p, how can I code?

Just a strange thought popping into my head.

L

1
2
3
int a{ 10 }, b{ 3 };
int* p{ &a };
int result{ *p * b };   // 30 
a*p[0];
What is the type of a and b?
Are they array or a variable?
I never see kind of declaration before. Would you please explain. Thanks.

So impossible to do *p * *p, which is to multiply two dereference?

L

What is the type of a and b?
Are they array or a variable?
I never see kind of declaration before. Would you please explain. Thanks.

It's known as uniform initialisation. It's the preferred way to initialise variables since C++11.
http://www.stroustrup.com/C++11FAQ.html#uniform-init


So impossible to do *p * *p, which is to multiply two dereference?

No? Why would that be the case?
1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    int a{ 10 };
    int* pa{ &a }; int** ppa{ &pa };
    std::cout << *pa**pa << '\n';
    std::cout << **ppa***ppa << '\n';
}


100
100

Depending on whether the asterisk is before or after a term will determine which operation is used; unary dereference for the former and binary multiplication for the latter.
Thank you! very helpful.
Topic archived. No new replies allowed.