Stylish pointer declarations

When you declare a pointer to float, it looks like this:

f​l​o​a​t​ ​*​p​o​w​e​r​P​t​r​;​

Because the type is a pointer to a float, you may be tempted to write it like this:

f​l​o​a​t​*​ ​p​o​w​e​r​P​t​r​;​

This is fine, and the compiler will let you do it. However, stylish programmers don’t.

Why? You can declare multiple variables in a single line. For example, if I wanted to declare variables x, y, and z, I could do it like this:

f​l​o​a​t​ ​x​,​ ​y​,​ ​z​;​

Each one is a float.

What do you think these are?

f​l​o​a​t​*​ ​b​,​ ​c​;​

Surprise! b is a pointer to a float, but c is just a float. If you want them both to be pointers, you must put a * in front of each one:

f​l​o​a​t​ ​*​b​,​ ​*​c​;​

Putting the * directly next to the variable name makes this clearer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset