473,503 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the real meaning of NULL?

26 New Member
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     int* a= NULL;
  4.     return 0;
  5. }
Here Integer pointer is assigned to NULL, I dont know
the complete meaning of NULL till now. I am assuming tat a particular memory location is named as "NULL" and the pointer's which are assigned to NULL, points to tat particular location. Can anyone clear this basic doubt for me.
Jan 24 '13 #1
5 1564
Banfa
9,065 Recognized Expert Moderator Expert
NULL is a macro, normally defined to ((void*)0) in C and plan 0 in C++.

NULL is a convenience to aid with the requirements of the language (C or C++). The language standards require that the value 0 when used in a pointer context is to be interpreted as and converted to the platforms NULL pointer value, that is a pointer that points nowhere.

Note there is no requirement that the platforms NULL pointer value actually has the value 0 although for a vast majority of platforms this is the case. The requirement is only when the compiler sees a 0 in a pointer context in the code it is converted to whatever value the platform does use for a NULL pointer; obviously an easy conversion if the platforms NULL pointer value is 0.

A NULL pointer nominally points no-where and trying to access what it points at is undefined behaviour and often, if you are lucky, produces some sort of memory exception or segmentation fault.
Jan 24 '13 #2
donbock
2,426 Recognized Expert Top Contributor
Notice that NULL is different than null. The first is a pointer value (as described earlier by Banfa); the second is a character value.
Jan 28 '13 #3
swapnali143
34 New Member
NULL is Macro Defined in C....
NULL is used as Constant......
Its used to terminate String...
Things to remember about NULL are.
NULL is NOT EQUAL to 0
and NULL is NOT EQUAL to '\0'
Jan 29 '13 #4
Banfa
9,065 Recognized Expert Moderator Expert
@donbock : I believe that the character is actually called nul or NUL (control characters tend to have 2 or 3 letter names)

@swapnali143 Well yes strictly speaking you are correct by the standard NULL is defined to an implementation defined null pointer value.

However in every compiler I have ever used (which is quite a few) NULL has always been defined to the value 0 or (void*)0 (depending on language) which works because of the requirement for the compiler to convert 0 used in a pointer context to the implementations null pointer value. That said you should of course never use NULL where you mean the value 0, it should only ever be used in the context of testing or assigning a pointer to the null pointer value.

Additionally what you say about terminating a string is wrong. NULL is not used to terminate a string; as you point out it can not be assumed to have the value 0 and the value 0 is specifically what you want when terminating a string. Strictly the character '\0' (or NUL but this is the name of the character '\0' not a defined constant) is used to terminate a zero terminated string which is what C uses.
Jan 29 '13 #5
donbock
2,426 Recognized Expert Top Contributor
@banfa You're correct -- I was wrong to say null means anything in particular. The C Standard uses that word in the following contexts.
  • null character: '\0'
  • the null wide character: L'\0'
  • null byte (within a multibyte character array)
  • null-terminated
  • null pointer constant: 0 or (void*)0 or NULL
  • null pointer: a null pointer constant cast to a pointer type
  • null statement: just a semicolon (;)
  • null preprocessing directive: just a hash (#)

The term NUL comes from the ASCII specification not the C Standard. It is the name of the ASCII character that is encoded as 0.
Jan 29 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1366
by: Boris Boutillier | last post by:
Hi all, I've got problems with the Py_TPFLAGS_HEAPTYPE and the new 'hackcheck' in python 2.3. I'm writing a C-extension module for python 2.3. I need to declare a new class, MyClass. For...
4
4091
by: bingfeng | last post by:
I have some codes generated by perl, in which initialize some huge struct,such as PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "", "configuration on a designated vlan",...
1
1950
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
3
3645
by: shivapadma | last post by:
1.when referenced pointer is not active then it is called dangling pointer. is this correct ? 2.the pointer which does not point to anything is called null pointer. is NULL macro is a...
31
2407
by: Tommy | last post by:
struct stat *stats IF_LINT (= 0); I don't know why "IF_LINT (= 0)" is needed ? Source is df.c of df program on Linux coreutils-5.2.1\coreutils-5.2.1\src Thanks!
4
1439
by: sam | last post by:
Hi, I just want to ask the question about this code int len =0; len =5; "x41" * (len); In this is "x41" is multiply by 5 or it just can acquire space like this x41x41x41x41x41 . I am a...
5
10726
by: Thiruvenkadam | last post by:
I know that null character have ascii value of 0 and space as 32.My question is what a NULL character will do.How to define it?
1
2246
by: Henry Yiu | last post by:
I am using the ReadFile() function in Visual C++. One of its parameter is a pointer which needs to point to a valid variable, but then it says that it can be NULL when another input flag parameter...
3
5542
by: jeyshree | last post by:
hai, will someone please explain me what is null pointer assignment error.different persons say different reasons.some says the following code would generate null pointer assignment error....
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.