473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Size of null

77
When i did printf("%d",sizeof(NULL));
answer is coming as 2 in Turbo C... Sizeof integer is also coming as 2... We cannot assume that null is of same size as integer.
Jan 9 '10 #1
5 8746
Banfa
9,065 Expert Mod 8TB
In that particular context yes but that might not be true for every context. Printing sizeof NULL is not very useful for understanding it you should really consider how it is defined, for C

#define NULL ((void*)0)

for C++

#define NULL 0

So for C++ it does appear that NULL is an integer. However you are correct that you should not assume that NULL has the same size as int. NULL is meant to be used in a pointer context, there where 32bit platforms that had 16bit integers and 32bit pointers and current 64bit platforms tend to have 32bit integers and 64bit pointers so NULL that is a pointer value very clearly does not have the same size as an int.
Jan 9 '10 #2
donbock
2,426 Expert 2GB
NULL is a value that can be stored in variables of certain types. The sizeof operator is not intended to be used with values -- it is meant to be used with types. If you want to know how large a data pointer can be then you should obtain the size of a pointer type. A convenient choice is
Expand|Select|Wrap|Line Numbers
  1. sizeof(void*)
Jan 11 '10 #3
Time
77
If it is really meant to be used with values and not types; it should have given error accordingly.. but this is not the case.
Jan 15 '10 #4
donbock
2,426 Expert 2GB
@Time
This is not the only place where C gives you enough rope to hang yourself.
Jan 15 '10 #5
Time
77
So being 'expert' in this forum; you must have made many attempts by now to hang up your-self with that rope provided by C :)
Jan 17 '10 #6

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

Similar topics

54
by: Neo | last post by:
Hi Folks, I've a simple qestion related to dynamic memory allocation in C here is the code: #include <stdio.h> int main() {
0
by: Raed Sawalha | last post by:
I'm capturing the screen using the following code , but the problem i have that after 43 calls of the functions the NULL reference object is returned , SIZE size; //Here we get the handle to...
27
by: Deephay | last post by:
Greetings all, I have a program that used the realloc() function to change the allocated size of a buffer, the program works with some arguments, but with some other arguments, it will show me...
20
by: asdf | last post by:
I got a warning from gcc for the following code if (nextIs_.size() == NULL) warning: NULL used in arithmetic how can I fix this problem? It seems that I can install a patch for gcc, but I...
3
by: Ganesh Palaniappan | last post by:
We're getting following exception for the below piece of code. We're wondering how it is possible since we're having a null check for objGraphics and strokePen... Exception:...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
43
by: Frodo Baggins | last post by:
Hi all, We are using strcpy to copy strings in our app. This gave us problems when the destination buffer is not large enough. As a workaround, we wanted to replace calls to strcpy with strncpy....
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
4
by: Kenneth Brody | last post by:
I looked at my copy of n1124, and I didn't see anything about this particular situation... What happens if you realloc() to a size of zero? Implementations are allowed to return NULL on...
9
by: Francois Grieu | last post by:
When running the following code under MinGW, I get realloc(p,0) returned NULL Is that a non-conformance? TIA, Francois Grieu #include <stdio.h> #include <stdlib.h>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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
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...

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.