By using *y, we access the actual value of x, the int that y points at. Now we declare y as a pointer to an int, and set it to point at x by storing x's address. We declare x as an int holding the value 12. Std::cout << "X is " << *y // Will print "X is 12" Take a look at the following example: int x = 12 The asterisk is used in declarations of pointers and to dereference a pointer, the ampersand is used to get the address of something. The two operators used in conjunction with pointers are the asterisk ( *) and the ampersand ( &). You can dereference it, meaning you can actually visit the house. It shows you where the house is so you can find it, but when you pass it around, you don't pass around the whole house. Pointers 101Ī pointer is like the street address of a house. The next occurence of the asterisk ( *) is in the for-loop body, where it is used as the dereference operator, which basically resolves a pointer to get the actual value. As this might be a different type (maybe a pointer to a char, who knows), this value is cast to a pointer to an uint8_t. This pointer is set to the address of the value which is the imageLine * NUM_LEDS * 3th element in the imagePixels array. It declares ptr as a pointer to a uint8_t. The first four variable declarations should be fairly simple, the fifth one is something C# does not have. The second and third line can be expressed more cleanly: uint8_t pixelNum
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |