answersLogoWhite

0

Computer Programming
C Programming
The Difference Between

What is difference between zero value and NULL strings?


Top Answer
User Avatar
Wiki User
Answered 2009-10-21 15:00:11
Answer

Programming languages store data in different data types. A zero value would belong to a numeric data type such as float, single, double, integer, long, etc. A null string is a variable that references a string (sequence of characters) that is not yet pointing to anything.

Answer

A null string can also be a string of zero length.


Answer
Several programming languages including C and C++ and several assembly languages store strings in "ASCIZ" format, also called "C string" format.
In those languages, a string variable contains only a pointer to the first character in the string, and the end-of-string is marked with the ASCII NUL character.
A programmer using strings in "ASCIZ" format must be aware of the two different ways that a string variable may store no characters:

One way a ASCIZ variable may store no characters:
A string variable may contain the null pointer constant, which is represented by the constant integer 0. All such "null pointers" point to the same location, represented by the constant integer 0, and often called NULL.
No valid string is ever located at that location.
For example,
char * winner_name = 0;
or equivalently
char * winner_name = NULL;
Typically a programmer must write explicit code to check for this possibility first.
For example,
if( winner_name ){ cout << " The winner is: " << winner_name << " !\n"; };

The other way a ASCIZ variable may store no characters:
The string variable may contain the address of a valid memory location that contains no other characters before the end-of-string NUL character.
Some programs have many such locations in memory, located at a variety of addresses (that address is stored in the string variable), that contain such a "null string" or "zero-length string".
For example,
char buffer[BUFFER_SIZE] = "";
or equivalently
char buffer[BUFFER_SIZE] = {'\0'};
.


Sometimes programmers can write the code that handles normal strings in such a way that that code also handles zero-length strings, with no explicit check for a "zero-length string" possibility.
001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Loading...

Still have questions?

Related Questions

What is difference between null value and not null value?

Putting it very simply a null value is empty and a not null value contains something.


What is the difference between Strings and Arrays in c?

There is no difference. A string is just an array of type char. The only real difference is that we do not need to keep track of the length of a string because strings are null-terminated in C. If a string does not have a null-terminator, then it is just an ordinary array of character values.


What is the difference between a null pointer and a null macro?

A null pointer is a pointer variable with the value 0. A null macro is a macro that defines the NULL symbol (typically 0L on a 32-bit system).


What are the difference between null and undefined in Javascript?

undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and nullare two distinct types: undefined is a type itself (undefined) while null is an object


What is the difference between equals 0 and equals NULL?

NULL is for pointers, 0, for numbers


What is the difference between 0 and null?

Nothing - 0, Zero and null are the same things


What is the difference between null in c and in oracle?

A NULL in C is a pointer with 0 value, which cannot be a valid address. A null in Oracle is the condition of not having a value, such as a field in a row being null, meaning that it does not have a value. This is not the same as zero - zero and null are two different things. Note, however, that Oracle does not differentiate between a null and a zero length string. This was an error in non-ANSI implementation made many years ago, but it has persisted because fixing it would impact too much "running" code.


What is the defualt value for String in java?

The default value for objects is null; I believe this would apply to a String, too, since Strings are objects.


Difference between null and empty in c plus plus?

NULL is a constant with the value zero. It is typically used with pointers to signify the pointer is valid, but it does not store a valid memory address. In other words it points at nothing in particular. It is nullified. All pointers that are not currently in use must be nullified to signify the fact they are not in use. The term empty applies to arrays that have no elements: empty arrays. We also use the term when referring to empty strings. A string is simply an array of char, but while null-terminated strings always have at least one char, the null-terminator, the string itself is empty.


What is the difference between zero vector and null vector?

They are the same.


What is the difference between a null hypothesis and a research hypothesis?

The null hypothesis is the default hypothesis. It is the hypothesis that there is no difference between the control group and the treatment group. The research hypothesis proposes that there is a significant difference between the control group and the treatment group.


What is the difference between strcpy and strncpy in c language?

strcpy is meant to copy only null-terminated strings. It is probably implemented to copy every byte until it encounters a #0. strncpy() copies n bytes and it adds null termination at the end of the target string.


How does the difference between fe and fo influence the outcome of a chi-square test?

The larger the difference, the larger the value of chi-square and the greater the likelihood of rejecting the null hypothesis


What is the difference between void pointer 0 and NULL.?

If by 'void pointer 0' you mean '(void *)0', then it is equal to NULL.


Difference between p value and level of significance?

P- value is the probability that the given null hypothesis is true and the level of significance is the chance in a hundred or thousand off occurence of an event i an outcome


What is the difference between array and string of array?

When we declare an array of characters it has to be terminated by the NULL , but termination by NULL in case of string is automatic.


What is the null value in DBMS?

its is just a blank value that is represented by the null word...


What is the difference between null pointer ASCII null character and null string?

A null pointer is a pointer which does not point to any valid memory location, and usually contains the binary value "0" to represent this (this is language dependent). The ASCII null character is a character-sized zero value (in ASCII, it is an unsigned byte with a value of 0), and typically represents the end of a string (esp. as in C and C++). A null string is one that is zero characters of usable string data; in a length-based string, this means the length parameter is set to 0, and in an ASCII null-terminated string, means the first character is set to 0.


What is the difference between two source hypothesis and two gospel hypothesis?

null


What is the difference between an array shift and unsetting a variable in PHP?

By shifting the values in an array, you are moving a key's value to the previous key. The very first key's value is obliterated. By shifting all values in the array, all keys will have a value of NULL. Unsetting a variable is entirely different -- performing a variable unsetting causes the variable to have a value of NULL, as if it was never set.


What is the major difference between the null and alternative hypothesis?

In research, a null hypothesis means that no results will be found. An alternative hypothesis means that results will be found.


What is the difference between Uninitialized pointers and Null Pointers?

Unitialized pointer may contain any value, so if you should use them, the results are unpredictable; NULL value on the other hands explicitly means that the pointer does not point anywhere. e.g.: size_t ListLen (const List *p) { size_t len= 0; while (p != NULL) { ++len; p= p-&gt;Next; } return len; }


What is difference between varchar and varchar2?

Character string values storage:1. CHAR:&sect; Stores strings of fixed length.&sect; The length parameter s specifies the length of the strings.&sect; If the string has smaller length it padded with space at the end&sect; It will waste of a lot of disk space.&sect; If the string has bigger length it truncated to the scale number of the string.2. VARCHAR:&sect; Stores strings of variable length.&sect; The length parameter specifies the maximum length of the strings&sect; It stores up to 2000 bytes of characters&sect; It will occupy space for NULL values&sect; The total length for strings is defined when database was created.3. VARCHAR(2):&sect; Stores strings of variable length.&sect; The length parameter specifies the maximum length of the strings&sect; It stores up to 4000 bytes of characters&sect; It will not occupy space for NULL values&sect; The total length of strings is defined when strings are given


What is a NULL Pointer?

A pointer variable which is declared but not initialized is called a NULL POINTER.ex: int *p;Please don't use the above. A NULL pointer is a specific value assigned to a pointer, just like any other value. NULL is a language-specific designation, and is guaranteed to be comparable to, unlike uninitialized variables, which can have any value.That is:int *a;int *b = NULL;int *c = (int *) malloc(sizeof(char));( a c) is NEVER true.NULL is a reserved word in most high-level languages, and indicates a specific value for assignment. It is commonly used to indicate that something has not yet been assigned a "real" value, or has had its contents deleted. It is an EXPLICIT value, and not just "undefined".In the context of pointers (which, remember, are really memory location addresses), a NULL pointer is one which has NO value, and thus does NOT point to any memory location. The difference between an uninitialized pointer and a NULL pointer is that most common languages do not specify what value an uninitialized pointer has upon creation (many, such as C, are assigned a random value), while a NULL pointer explicitly has NO value (which is the meaning of NULL).Many modern languages and compilers will assign NULL to a pointer upon initialization, but don't count on it. It is sloppy programming to do so, and can lead to many hard-to-find errors.


What is the difference between void pointers and null pointers?

A void pointer is a pointer that has no type information attached to it.A null pointer is a pointer that points to "nothing". A null pointer can be of any type (void included, of course).