1.What is diffrence Between NULL and '/0' characters?
2.Does the last cell os a string has NULL or '/0'?

Gooooooogle got me this URL. \0 is the null terminator to a string. It's sometimes handy with all arrays to have a unique terminator, but usually not possible.

NULL is a macro defined in <stddef.h> for the null pointer.

Its not '/0' its '\0'

'\0' is defined to be a null character, a character with all bits set to zero.Used as end of string.

seanbp,Thanq but still its abstract for me

All the functions found in string.h expect character arrays to be terminated with a '\0' character. For example char Hello[] = {'H','E','L','L','O','\0'} An easier way to code the same is char Hello[] = "Hello"; In that case the compiler will add the '\0' character to the end of the string for you.


NULL is a macro which is normally used with pointers, such as char* Hello = NULL; The exact definition of NULL is compiler dependent, but normally defined as either (char *)0 or just 0.

BTW there is no difference between '\0' and 0, they are interchangable.

>The exact definition of NULL is compiler dependent, but normally defined as either (char *)0 or just 0.
I haven't seen NULL defined as (char*)0 and I don't suspect any compilers have done so after the generic pointer type was introduced to C. While char* and void* have the same alignment properties, the implicit conversion rules of void* don't apply to char*, and use of NULL (if defined as char*) would require rather liberal casting. The two most common definitions are:

#define NULL 0

and

#define NULL ((void*)0)

>BTW there is no difference between '\0' and 0, they are interchangable.
Though the usual advice applies. Prefer NULL only for pointer context, '\0' only for character context, and 0 when NULL and '\0 don't apply. Not only does this guideline improve the clarity of one's code, it also avoids sticky typing issues that may arise in C and most certainly arise if C++ compatibility is a goal.

But Remember difference between char '0' and mathematical '0' ..

>>I haven't seen NULL defined as (char*)0

Most MS-DOS compilers defined it that way before c++ and void keyword were invented. But of course you are correct that void* is now used instead of char*.

Hey,Thank U Guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.