自动C 关键字有什么作用

What does the auto c++ keyword do?

本文关键字:什么 作用 关键字 自动      更新时间:2023-10-16

我最近在C 中获得了关键字自动。

在代码中:

auto maxIterator = std::max_element(&spec[0], &spec[sampleSize]);
float maxVol = *maxIterator;
// Normalize
if (maxVol != 0)
  std::transform(&spec[0], &spec[sampleSize], &spec[0], [maxVol] (float dB) -> float { return dB / maxVol; });

这与在音频流上运行频率分析有关。从网站:http://katyscode.wordpress.com/2013/01/16/cutting-your-teeth-teeth-fmod-part-part-part-4-frequency-4-frequency-analysis-graphic- equarpaphic-equalizer-equalizer-beat-detection and-bpm-估计/

我搜索了论坛,但它说关键字没有用。有人可以在这里解释它的用途吗?

我是C 的新手,所以请尽量不要使答案变得太复杂。非常感谢。

自动使麦克西托也成为指针吗?

编译器猜测maxIterator的类型。如果spec的类型为float [],则maxIterator类型为float *

在C 11中,关键字auto从其初始化表达式中推论已声明的变量的类型。因此,在您的代码中,它推论了maxIterator的类型。

有关auto的更多信息,请