Question:
Is NULL always defined as 0?
Answer:
NULL is defined as either 0 or (void*)0. These values are almost identical; either a literal zero or a void pointer is converted automatically to any kind of pointer, as necessary, whenever a pointer is needed (although the compiler can’t always tell when a pointer is needed). Source: CoolInterview.com
#include<stdio.h> int main() { if(NULL==(void *)0) printf("true"); else printf("false");
if(NULL == 0) printf(" Value is zero"); getch(); } This gives the output as True Value is Zero Source: CoolInterview.com
Answered by: Syed Baseer Ahmed | Date:
| Contact Syed Baseer Ahmed
NULL in c is defined as a macro in stdio.h as #define NULL 0 as we know that we don't have to include the stdio directive we can access the NULL Source: CoolInterview.com
Answered by: mahanth hiremth | Date: 1/28/2010
| Contact mahanth hiremth
it's depend on system but default is zero.... Source: CoolInterview.com
Answered by: khaja | Date: 2/11/2010
| Contact khaja
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|