Multiple Pointer Declarations

Quick quiz:

What does the following code do:

char* p1, p2


Hopefully, you recognized that despite the fact that the asterisk is attached to the word char, we’re NOT creating two character pointers. Instead, we’ve created one pointer (p1) and one char variable (p2). Thus, the following are legal:

*p1 = 'C';
p2 = 'd';
p1 = &p2;
p1 = malloc(10*sizeof(char));

Leave a Reply

Your email address will not be published. Required fields are marked *