© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

9. What is the difference between NULL and NUL?

Ans:
NULL is a macro defined in for the null pointer.
NUL is the name of the first character in the ASCII character set. It corresponds to a zero value.

Ex - 1:  What is the output?
main()
{
                        int i = 257;
            int *iPtr = &i;
                        printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}

Ans:
                        1 1

Explanation:

The integer value 257 is stored in the memory as, 00000001 00000001, so the individual bytes are taken by casting it to char * and get printed.

Ex - 2 what is the output?:

main()
{
                        int i = 258;
            int *iPtr = &i;
                        printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}    
    
Ans:
                        2 1

Explanation:

The integer value 257 can be represented in binary as, 00000001 00000001. Remember that the INTEL machines are ‘small-endian’ machines. Small-endian means that the lower order bytes are stored in the higher memory addresses and the higher order bytes are stored in lower addresses. The integer value 258 is stored in memory as: 00000001 00000010.  


SLogix Student Projects
bottom