why can't we change the default starting index of an array to 1 instead of 0 ?
and another question how much fields can a bit field have ay most ?
thanks previously

Recommended Answers

All 4 Replies

This is a common question for a new C or other language programmer. To know why I guess you could find books on the history of C and how it came to be. But it's mostly historic and you can code as you see fit. However, it is best to not fight the tide this time and learn how to code using the standard calls and accept that arrays and more start at zero.

As to the bit field question, that varies with the storage you chose. For Integer Types (noted at https://www.tutorialspoint.com/cprogramming/c_data_types.htm ) you have 1 to 4 bytes and since a byte (for most machines) is 8 bits that would be 8 fields per byte.

This can be considered arcana today by some. Let's say you are programming on an average PC today. Not much reason to encode data into bit fields. Just use variables to clearly state what you mean. In embedded programming bit fields are not going away. Some will open a debate on this. I think this quote applies here.

This has made a lot of people very angry and been widely regarded as a bad move.

Douglas Adams

Going back to Kernighan & Ritchie...

An array name is a pointer expression ... a reference to an array is converted by the compiler to a pointer to the beginning of the array ... a reference to a[i] can also be written as *(a+i)

Obviously this implies that the first element of an array MUST be [0]

@rproffitt Thanks for the clearance i see now so it's just all about the makers and that's that, just seems we should use it the way it was invented to be heh.

You could always switch to a language where indexing starts at 1. FORTRAN, Lua, Pascal and Smalltalk to name a few.

commented: Oh Pascal, where I spent too much time. +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.