Here is my code snippet
main() {
char *filename;
if(1 > 2) {
filename = "file.txt"
}
if(filename != NULL (also tried 0) {
do something
}
return 0;
}
My question is how to check if filename var have assigned value. I can use strcmp but rvalue can be different of “file.txt”
Change:
To:
Then your
NULLtests will work.When you don’t initialize this pointer, its value is undefined. That’s why your tests were failing. The compiler assumed that you didn’t care what value it had.