小编Nee*_*der的帖子

char *name[10] 和 char (*name)[10] 有什么区别?

我对这两个符号表示什么感到非常困惑。我知道 的优先级()大于[],这是否意味着它char(*name)[10]是一个指针并且char *name[10]是一个数组?

c arrays pointers declaration implicit-conversion

3
推荐指数
2
解决办法
406
查看次数

这个警告在 C++ 中对于异常处理意味着什么?

我为除法运算编写了一个异常处理代码:
我包含了Zero division error, Negative value error(不是异常,但我包含了它!)和Indeterminate form error(我也包含了它)。

然后在编译后它显示一些警告,但.exe文件按预期运行。
这是我在编译后收到的代码和输出。

代码

#include <iostream>
#include <stdexcept>

using namespace std;

int main(void)
{
    int numerator, denominator, quotient, remainder;
    cout << "Enter the value of numerator and denominator: ";
    cin >> numerator >> denominator;
    try
    {
        if (!numerator && !denominator)
        {
            throw logic_error("Logical Error: Indeterminate Form!\n");
        }
        else if (!denominator)
        {
            throw runtime_error("Math Error: Attemp to divide by zero!\n");
        }

        else if (numerator < 0 …
Run Code Online (Sandbox Code Playgroud)

c++ exception try-catch

1
推荐指数
1
解决办法
70
查看次数

为什么在 C 中迭代这样的数组效率低下?

我正在读一本书,其中有这一段:

C 中的数组可以看作是一块连续的内存。更准确地说,数组的最后一维是连续部分。我们称之为行优先顺序。了解这一点以及在访问未缓存的数据时缓存错误将完整的缓存行加载到缓存中以防止后续缓存错误的事实,我们可以理解为什么使用 array[0][0] 访问维度为 10000x10000 的数组可能会加载 array[ 0][1] 在缓存中,但随后访问 array[1][0] 会产生第二个缓存错误,因为它与 array[0][0] 相距 sizeof(type)*10000 字节,因此肯定不是在同一缓存线上。这就是为什么这样迭代效率低下的原因:

#define ARRLEN 10000

int array[ARRLEN][ARRLEN];
size_t i, j;

for (i = 0; i < ARRLEN; ++i)
{
    for(j = 0; j < ARRLEN; ++j)
    {
        array[j][i] = 0;
    }
}
Run Code Online (Sandbox Code Playgroud)

您能否向我解释一下他们在本段中试图解释的内容以及他们所谈论的“缓存故障”是什么?

c arrays iteration row-major-order

0
推荐指数
1
解决办法
101
查看次数

C++ 中的@ 是什么,为什么在 C++ 头文件中使用它?

我正在查看queue头文件C++并找到了一段代码。

来自队列头文件的一段代码

#include <debug/debug.h>
#include <bits/move.h>
#include <bits/predefined_ops.h>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  /**
   * @defgroup heap_algorithms Heap
   * @ingroup sorting_algorithms
   */

  template<typename _RandomAccessIterator, typename _Distance,
       typename _Compare>
    _GLIBCXX20_CONSTEXPR
    _Distance
    __is_heap_until(_RandomAccessIterator __first, _Distance __n,
            _Compare& __comp)
    {
      _Distance __parent = 0;
      for (_Distance __child = 1; __child < __n; ++__child)
    {
      if (__comp(__first + __parent, __first + __child))
        return __child;
      if ((__child & 1) == 0)
        ++__parent;
    }
      return __n;
    }
Run Code Online (Sandbox Code Playgroud)

@它是什么以及为什么在多行注释中使用它。后面的文本@也在我的 IDE …

c++ comments operators header-files

-1
推荐指数
1
解决办法
73
查看次数