C++/pointers

Advertisement


Question

Hello, Bill

I was wondering what is the difference between
*d and d*. Assume that d is a variable of any primitive type

Thanks

Answer
Hello,

*d works only when d is a pointer (to some type) and it's value is an object of that type.  If it's int *d; then *d load the int pointed to by d.

d* is valid only with a following expression (which could be a simple variable or number) and multiplies d by that expression.  For int d; d * 4 is of course the value of d times 4.

Bill

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill A

Expertise

I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.

Experience

I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Publications
Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

Education/Credentials
BS Computer Engineering

©2016 About.com. All rights reserved.