C/C++ NaN constant (literal)?

后端 未结 5 875
孤独总比滥情好
孤独总比滥情好 2020-11-29 21:20

Is this possible to assign a NaN to a double or float in C/C++? Like in JavaScript you do: a = NaN. So later you can chec

5条回答
  •  情话喂你
    2020-11-29 21:57

    yes, by the concept of pointer you can do it like this for an int variable:

    int *a;
    int b=0;
    a=NULL; // or a=&b; for giving the value of b to a
    if(a==NULL) 
      printf("NULL");
    else
      printf(*a);
    

    it is very simple and straitforward. it worked for me in Arduino IDE.

提交回复
热议问题