Hey everyone,

I'm coding a program in C and have a pointer called pRoot. I need to do (2 * pRoot) .. but the compiler says I cannot. Is there some legal way of implementing this pointer arithmetic?

Thanks in advance for your help!

Recommended Answers

All 4 Replies

The compiler warns because generally it isn't what someone wants. But multiplying by two is the same as adding self to self.

[edit]Heh. But that won't work with pointers. Probably also for good reason.

The compiler warns because generally it isn't what someone wants. But multiplying by two is the same as adding self to self.

the compiler is actually giving an error though -- "invalid operands to binary *"

the compiler is actually giving an error though -- "invalid operands to binary *"

What kind of meaning do you expect for (2 * pRoot)?

>the compiler is actually giving an error though -- "invalid operands to binary *"
The compiler is actually right. Multiplication for pointers is nonsensical. Why don't you tell us what you're trying to do and we can tell you how to go about it, because you clearly need someone to protect you from yourself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.