represent False a: the null pointer B:a floating expression haveing the value 0.0 C: the null character '\0' D: all of the above.
In C, Fales is represented by an expression with a value of 0. choose the valid expression that can be used to
Sure - let's take 'em all. The answer is D.
(C WILL TREAT NULLS AS FALSE. Period. Perhaps someone is thinking of SQL and other languages where NULL != 0, but that's NOT the case in C.)
Null pointers are often returned from functions indicating failure. Thus, null pointers can be tested as false.
Null character '\0' ( 00 000 000) itself is zero and will equate to false.
Value of 0, whether 0.0 as a double or float, int, short, long, etc, is still zero and will equate to false.
Have a look with this program:
#include %26lt;stdio.h%26gt;
int main() {
char myChar='\0';
double myDouble=0.0;
char * myPtr = NULL;
if ( ! myChar )
printf ("NOT MyChar - FALSE\n");
else
printf ("myChar - TRUE\n");
if ( ! myDouble )
printf ("NOT myDouble - FALSE\n");
else
printf ("myDouble - TRUE\n");
if ( ! myPtr )
printf ("NOT myPtr - FALSE\n");
else
printf ("myPtr - TRUE\n");
}
"testit.c" 27 lines, 367 characters
reznet1__/disc12/users/resnimi-%26gt; make testit
cc -O testit.c -o testit
reznet1__/disc12/users/resnimi-%26gt; ./testit
NOT MyChar - FALSE
NOT myDouble - FALSE
NOT myPtr - FALSE
Reply:its B. the null value refers to empty meaning no value at all so it cannot be equal to zero. and the only B can be used to represent false is if you typecast it to int since int and float have different memory allocations
Reply:B. All of the other answers include NULL. Null doesn't have a value. Null != 0. Always remember that. Even a floating expression with a value of 0 will be 0. NULLS are not 0.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment