Is this code (simplified from a real project) correct? Will the message always print?
char *cp = NULL;
char **cpp = &cp;
if(*cpp == NULL) {
printf("I believe this will this always print. Does it?\n");
}
Thanks!
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.
Yes, it will always print.
You can safely assume that your base stack pointer never points to 0x0, so &cp will always not equal NULL.
In fact the compiler will eliminate the check at compile time, because it knows
&cp != NULL.See for yourself:
Compiled with
-O1:(With
-O0there will be a test, though:)