# Tag Info

### Why do we count starting from zero?

None of the reasons you suggest really get to the heart of why we use zero-indexing in CS. Dijkstra's EWD831 explains why this convention works out the best. It comes down to the fact that we want to ...
• 1,819

### Why do we count starting from zero?

If I can modify the question, I can answer what I believe you are looking for. The question is "Why do we count starting from zero?" The answer is "we don't" Not even in computer science do we "count"...
• 5,445

### Why do we count starting from zero?

I'm surprised that the following hasn't been stated yet. All of the answers given so far seem to be "after the fact" explanations of something that is really based on the way people built most (not ...
• 36.4k

### Real life examples of 0-indexing

You can get at this concept very intuitively in strings before you ever get to arrays. Take a string like "hello world" and ask them a subtle-sounding point: does the string begin here: ...
• 33.9k

### Real life examples of 0-indexing

Ages in the United States (it's not the same around the world). For the first year of life, children are 0 years old. Only after completion of a year is the age changed to 1. By this logic, a child ...
• 9,102

### Why do we count starting from zero?

You have already gotten several good answers about why zero-based indexing is useful, and you have been explained the difference between indexing and counting. I now want to challenge the basic ...
• 1,426

### Real life examples of 0-indexing

An analogy that will work well in Europe, but not in North America: Image licensed under the CC BY-SA 3.0 by Bidgee of Wikimedia Commons. Floors (in European countries) are typically numbered with 0 ...
• 3,536
Accepted

### How to respond to the two-handed approach to swapping

Don't overcomplicate things. Your first instinct, that the computer only has one hand, was the correct one. This is a regular problem that new teachers have, and it sometimes takes a few years of ...
• 33.9k

### Real life examples of 0-indexing

The clock (24 hours system) If we look at the clock, we have two examples of counting hours. The 24 hour system starts at 0. The 12 hour system is interesting, neither starting at 0 or 1. The 12-hour ...
• 10.8k

### Why do we count starting from zero?

When I've explained this to beginning students, I don't stray far from your third reason, though I agree that the beginning of arrays is early to introduce the concept of memory addresses. Among ...
• 33.9k

### How to respond to the two-handed approach to swapping

Re-evaluate what you think is "right", because you aren't but isn't right in computer science This is simply incorrect. Your student can create two variables called ...
• 1,072

### How to respond to the two-handed approach to swapping

Your problem is that you tried to let your student "program" without establishing a language. Thus they were free to write their own "language" in which you can do two things at ...
• 1,523

### Real life examples of 0-indexing

I don't see anything confusing in 0-based indexing. In fact, it seems that 0-based indexing is not less natural for humans than 1-based indexing. Humans use 1-based indexing just because of following ...
• 320

### Lesson Idea: Arrays, Pointers, and Syntactic Sugar

You overestimate the complexity of 0-based indexing a lot. There is nothing complex in 0-based indexing. On the other side, the topic of the pointers is relatively complex. I don't think it has any ...
• 320

### Lesson Idea: Arrays, Pointers, and Syntactic Sugar

This is a great explanation of why 0-indexing exists. As someone who barely knows what a pointer is, your explanation made perfect sense. If you wanted to dumb it down a little you could phrase it as: ...
• 4,795

### Why do we count starting from zero?

In computer science, we usually count starting from 0. In programming or in (theoretical) computer science? In Programming In C programming language you count from 0 to (N-1). And of course in ...

### Real life examples of 0-indexing

Exponents representing the values of the digits in positional number systems. e.g. the-arabic-system / denary / the-system-you-learnt-in-primary-school. ...
• 10.8k

### Real life examples of 0-indexing

Rulers start at zero: At zero centimetres, you have nothing, whereas at one centimetres, you have one unit of length. Memory is similar: You start filling at the beginning (zero), hence, the first x-...
• 281

### Why do we count starting from zero?

In languages such as C, the first item in an array has an offset of zero from the pointer. If the size of your objects are 4 bytes, the next item has an offset of 1 x 4 bytes. ...
• 209
Accepted

### Array or vector? Two dimensional array or matrix?

First, see this question on being pedantic. Second, consider the fact that you are teaching Computer Science and not Mathematics. The former is not a subset of the latter. There is some overlap, of ...
• 36.4k

### Single-dimensional array and simple looping activities of significance

The Dutch National Flag problem is linear in running time. Essentially sort an array with only 3 distinct values each of which may appear 0 or more times. (not length 3). You are allowed only one pass ...
• 36.4k

### Single-dimensional array and simple looping activities of significance

A variant on the ENIGMA machine encryption works well in a single loop, and is sufficiently complex to give students a real challenge. The core idea of the ENIGMA machine for this assignment is that (...
• 33.9k

### Why do we count starting from zero?

Simply put, we do not count from zero, we shift from zero You can think C as a neat way to not write different assembly for every architecture/machine/processor in existence. Instead, take a simple ...

### Array or vector? Two dimensional array or matrix?

I believe that the CS notion of a vector is not related to the concept of a vector as a fixed size set of components, and rather comes from the idea of a rank 1 tensor (which is also called a vector). ...
• 4,795

### Array or vector? Two dimensional array or matrix?

You are correct and incorrect at the same time. Nomenclature is important when teaching, and when programming. Being pedantic about nomenclature is a slipper slope and a morass. As noted by @Buffy in ...
• 5,445

### Lesson Idea: Arrays, Pointers, and Syntactic Sugar

Draw ongoing attention to the potentially confusing point by banning cardinal descriptions of an element's position. Avoid referring to the "first element" or "second element" and talk only about "...
• 1,843

### Why do we count starting from zero?

I will try to answer, without reference to low-level programming (or any programming language), without mention of history, or much maths. As already stated in some answers, we do not count from zero ...
• 10.8k

### Why do we count starting from zero?

From time to time I have had to do numerical work in MATLAB and the 1-based indexing always stuck out like a sore thumb, so I have a few examples I can provide where 0-based indexing is advantageous. ...
• 261