473,569 Members | 2,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 1569
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
1369
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 this class I want two things : 1) redefine the setattr function on objects of this class (ie setting a new tp_setattro)
4
4105
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", PRO_REQUIRED }; const char* TOS_network_spantree_set_0_para_1_emvalue = { "disable", "enable", NULL }; PARA TOS_network_spantree_set_0_para_1 = { "",...
1
1957
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 this. It is the part of the Streamreader class that creates a StreamReader instance for a given Stream. The next entry however I don't understand:...
3
3656
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 value for null pointer? 3.then what is void pointer?
31
2424
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
1452
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 newbie and i am confused , If you can't understand this question i am sorry, but i just want the clarification of this code.
5
10741
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
2247
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 is set to certain state. So my question is, if I do not set the flag to that state, and still set the pointer to NULL, will this error being caught...
3
5548
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. #include<stdio.h> #include<conio.h> main() { int *p=NULL; *p=10 getch(); }
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.