scy @scy@chaos.social · activity timestamp 8 min. ago Snarky, but a good point.#CPP #CPlusPlus Read more Read less Translate Translate alt Screenshot from a C++ tutorial: Warning Although you generally should not declare multiple variables on a single line, if you do, the asterisk has to be included with each variable. int* ptr1, ptr2; // incorrect: ptr1 is a pointer to an int, but ptr2 is just a plain int! int* ptr3, * ptr4; // correct: ptr3 and ptr4 are both pointers to an int Although this is sometimes used as an argument to not place the asterisk with the type name (instead placing it next to the variable name), it’s a better argument for avoiding defining multiple variables in the same statement. Screenshot from a C++ tutorial: Warning Although you generally should not declare multiple variables on a single line, if you do, the asterisk has to be included with each variable. int* ptr1, ptr2; // incorrect: ptr1 is a pointer to an int, but ptr2 is just a plain int! int* ptr3, * ptr4; // correct: ptr3 and ptr4 are both pointers to an int Although this is sometimes used as an argument to not place the asterisk with the type name (instead placing it next to the variable name), it’s a better argument for avoiding defining multiple variables in the same statement. #cplusplus #cpp Reply Boost Quote Like More actions Copy link Share View remotely Get latest replies Flag this post Block
alt Screenshot from a C++ tutorial: Warning Although you generally should not declare multiple variables on a single line, if you do, the asterisk has to be included with each variable. int* ptr1, ptr2; // incorrect: ptr1 is a pointer to an int, but ptr2 is just a plain int! int* ptr3, * ptr4; // correct: ptr3 and ptr4 are both pointers to an int Although this is sometimes used as an argument to not place the asterisk with the type name (instead placing it next to the variable name), it’s a better argument for avoiding defining multiple variables in the same statement. Screenshot from a C++ tutorial: Warning Although you generally should not declare multiple variables on a single line, if you do, the asterisk has to be included with each variable. int* ptr1, ptr2; // incorrect: ptr1 is a pointer to an int, but ptr2 is just a plain int! int* ptr3, * ptr4; // correct: ptr3 and ptr4 are both pointers to an int Although this is sometimes used as an argument to not place the asterisk with the type name (instead placing it next to the variable name), it’s a better argument for avoiding defining multiple variables in the same statement.