473,394 Members | 1,887 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,394 software developers and data experts.

hi may be it is a simple question

4
why numeric arrays don't end with a '\0'.
Jan 18 '08 #1
14 1489
sicarie
4,677 Expert Mod 4TB
why numeric arrays don't end with a '\0'.
Well, what is your guess?

Hint: how big are 90% of the numbers you use in an average day? How big are the sentences you use?
Jan 18 '08 #2
RedSon
5,000 Expert 4TB
Hint: how big are 90% of the numbers you use in an average day? How big are the sentences you use?
Answer is four, and eleventy-two.
Jan 18 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Zero is a valid number. If it means the end of the numeric array then you couldn't use zero for data. Not good.

In the case of chars, though, no char has a value of 0. OK, so why didn't they use 1 since no char has a value of 1. I don't know. I wasn't there at the time.
Jan 18 '08 #4
RedSon
5,000 Expert 4TB
Zero is a valid number. If it means the end of the numeric array then you couldn't use zero for data. Not good.

In the case of chars, though, no char has a value of 0. OK, so why didn't they use 1 since no char has a value of 1. I don't know. I wasn't there at the time.
"\0" also stands for NULL. NULL is kind of a problem because it's this mythical creature that exists where it is supposed to be the "absence of data" but usually it is represented by zero. So in some cases NULL and 0 are used interchangeably and can cause problems. At a higher level NULL is not supposed to be a number or a letter, it's not supposed to be anything. So you might be running into that issue some time.
Jan 18 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
Yeah. Fortunately, there is no NULL in C++.
Jan 18 '08 #6
RedSon
5,000 Expert 4TB
Yeah. Fortunately, there is no NULL in C++.
Fortunately?! I think not, kind sir!
Jan 18 '08 #7
why numeric arrays don't end with a '\0'.

You know all char, int etc stores as a number only. In case of Char, it is store as number called ascii value. Every character has some ascii value. Then you can make \0 as teminal point i.e. special ascii number. But In case of Integer, every number may be used . so there is no number left for idenfying termination. So You can'nt make \0 as terminal point in case of Integer,double( any Numeric data).



Asadullah Ansari
Jan 22 '08 #8
weaknessforcats
9,208 Expert Mod 8TB
Fortunately?! I think not, kind sir!
Your C is showing.

C++ is another language.
Jan 22 '08 #9
RedSon
5,000 Expert 4TB
Your C is showing.

C++ is another language.
Oh, how embarrassing, I'll zip that right up.
Jan 22 '08 #10
oler1s
671 Expert 512MB
why numeric arrays don't end with a '\0'.
How does that make sense? First, \0 is a character. Second, why would numeric arrays need an End of data indicator?

"\0" also stands for NULL. NULL is kind of a problem because it's this mythical creature that exists where it is supposed to be the "absence of data" but usually it is represented by zero.
You confuse the null character with the NULL macro, which is an implementation defined constant. The null character, however, is defined by standard as the character '\0' sometimes refered to as NUL or the like.

Yeah. Fortunately, there is no NULL in C++.
I believe it is defined in C++. I have to dig out a draft of the standard to get the exact wording, but IIRC, NULL is an implementation defined constant expression, and that constant should evaluate to 0. It's preserved for C compatibility.

In C++, NULL is really an embarassing mess, with 0 being abused for the null pointer. I believe C++0x is trying to rectify this with an actual first class nullptr keyword and the like.
Jan 22 '08 #11
ppd
4
I think the null character of character strings was chosen to denote the end of a string of characters - in the sense of when developing the character string built-in functions, one must have a way of knowing when a character string ends.
When the null character is encountered, a program such as strlen knows when to stop counting, or strcat knows when to start catting, ...
An array of numbers ends when there are no more numbers.
There is no need to have a special character to tell a program when to stop.
Jan 23 '08 #12
oler1s
671 Expert 512MB
An array of numbers ends when there are no more numbers.
Yes, but you can't check for "no more numbers". You must know the bounds of the array.
Jan 23 '08 #13
weaknessforcats
9,208 Expert Mod 8TB
I believe it is defined in C++.
NULL is not a C++ keyword.

This is not to say that some kindly person has not stuck in a #define NULL 0 somewhere to keep old dogs happy.
Jan 23 '08 #14
oler1s
671 Expert 512MB
NULL is not a C++ keyword.
No, it's not. It's a macro. I think it's defined in one of the C headers.

This is not to say that some kindly person has not stuck in a #define NULL 0 somewhere to keep old dogs happy.
Which is actually a technically wrong thing to do, because the definition of NULL is implementation specific. Technically it's a constant integral expression that eventually resolves to 0, so technically speaking, NULL isn't necessarily directly defined as 0. It's all a whole lot of awkwardness for C compatibility.

I don't want to go into a standards war, when we both agree on that NULL doesn't belong in modern C++ code. Scott Meyers indicated a null pointer idiom in one of his books; the code template should be Googleable.
Jan 23 '08 #15

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

Similar topics

3
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
1
by: Proteus | last post by:
Any help appreciated on a small perl project I need to write for educator/teaching purposes. I have not programmed perl for some time, need to get up to speed, maybe some kind souls hrere will help...
2
by: Raskolnikow | last post by:
Hi! I have a very simple problem with itoa() or the localtime(...). Sorry, if it is too simple, I don't have a proper example. Please have a look at the comments. struct tm *systime; time_t...
3
by: Peter | last post by:
Hello Thanks for reviewing my question. I would like to know how can I programmatically select a node Thanks in Advanc Peter
7
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
14
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...

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.