dimanche 1 octobre 2017

NULL pointer as condition of if stament [duplicate]

I wonder why the output is not as I expected. Calling the function print at the first time, the if statement is none, so the out put should be aa, why IPtr isNULL, therefore, you see this instead?

   #include<stdio.h>

   void print(int *wm);

   int main()
   {
       int * IPtr;
       printf("%d\n", IPtr == NULL);
       print(IPtr);
      // After executing this statement, it's supposed to print <aa> on the screen.

      int a;
      IPtr = &a;

      print(IPtr);

      return 0;
  }

  void print(int *wm){
      if(wm){printf("IPtr is null, therefore, you see this\n");}
      else{ printf("aa\n");}
  }

Aucun commentaire:

Enregistrer un commentaire