gpt4 book ai didi

language-agnostic - 在基于0的索引系统中,人们将索引0处的元素称为 "first"还是 "zeroth"元素?

转载 作者:行者123 更新时间:2023-12-04 04:43:17 24 4
gpt4 key购买 nike

例如,在Java/C++中,您是否随便说'a'"abc"的第一个字符,还是第零个字符?

人们会同时说这两种说法,而且总是模棱两可,还是有实际的约定?

维基百科对Zeroth文章的引用:

In computer science, array references also often start at 0, so computer programmers might use zeroth in situations where others might use first, and so forth.



这似乎支持这样的假设,即该假设将始终是模棱两可的。

感谢Alexandros Gezerlis( see his answer below)在 chapter 7的Allen B.Downey,Jeffrey Elkner和Chris Meyers的《如何像计算机科学家一样思考:用Python学习》中找到此报价:

The first letter of "banana" is not a. Unless you are a computer scientist. For perverse reasons, computer scientists always start counting from zero. The 0th letter (zero-eth) of "banana" is b. The 1th letter (one-eth) is a, and the 2th (two-eth) letter is n.



这似乎表明,作为计算机科学家,我们在处理基于0的索引系统时应拒绝“第一”,“第二”等自然语义。

这句话表明也许某些语言有官方规定,所以我将这个问题设为 [language-agnostic]

最佳答案

它是数组中的第一个字符或元素,但它的索引为零。

关于language-agnostic - 在基于0的索引系统中,人们将索引0处的元素称为 "first"还是 "zeroth"元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2600613/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com