Advertisement
obernardovieira

Check if pointer is not initialized (very easy)

Jul 11th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. //well, I do not know if this is correct, I was trying to check if a pointer had not been started
  2. //when I remembered to do that! and it worked
  3.  
  4. #include <stdio.h>
  5.  
  6. int main(void) {
  7.     int* allval;
  8.     if(allval == (int*)0) {
  9.         printf("sim\n");
  10.     }
  11.     else {
  12.         printf("nao\n");
  13.     }
  14.    
  15.     allval = (int*)malloc(5 * sizeof(int));
  16.     if(allval == (int*)0) {
  17.         printf("sim\n");
  18.     }
  19.     else {
  20.         printf("nao\n");
  21.     }
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement