Newbie to C, Pointers giving error ('p1' undeclared first use in this function) [closed]

Look, you know how to declare an integer, char, and float, because you did that already.

You also have to declare Pointers too:

int*   p1;   // p1 is a Pointer-to-Integer. 
char*  p2;  // p2 is a Pointer-to-Char.
float* p3; // p3 is a Pointer-to-Float. 

p1 = &integer;  // Set p1 to point to a real object.
p2 = &character;// Set p2 to point to a real object.
p3 = &pies;     // Set p3 to point to a real object.

Edit

OP asks about:

int p1 = &integer;  // WRONG: This only declares an int, not a Pointer-to-Int.

The * is very important to making a pointer.

If you want, you can do:

int*   p1 = &integer;  // Create a pointer, and set what it points to on one-line.
char*  p2 = &character;
float* p3 = &pies;

Leave a Comment