How can I write an if statement which tells the program if the pointer is assigned or not?
WRONG example
if (*badpdr[0]==0);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You mean
if (badptr==NULL)?Note that you have to initially set your pointer to NULL when you define it or when you “unassign it” (e.g., you delete the object it refers to). Otherwise, it will contain junk and this test would fail because the value would not be a 0.
You can also do the comparison to 0 instead of NULL, there’s already enough arguments on SO which is the correct form so I won’t repeat them.