C / C++ Error: Pointer Variable Undefined Inside Function

From my Java experience it was not hard to get a grip.

A pretty simple function:

void update(float * p,float value)
{
    *p = value;
}

The compiler is complaining that identifier p is undefined.

I thought *p would dereference the pointer and store value in it.

6

1 Answer

OK, so your code looks right, I have to assume the error message is coming from somewhere else. You can try out this "full" version of your program:

#include <stdio.h> 

void update(float *p, float value){
  *p = value;
}

int main(int argc, char *argv[]){  
  float p = 3.0;
  update(&p, 5.0);
  printf("%f\n", p);
}

Just copy and paste that and respond with any error/warnings you get. If it works fine, then you've miss typed something in your code, if it still gives you issues there's something up with your environment and we'll need more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest