小编lur*_*ker的帖子

这个函数中的数组之后++做了什么?

void doSomething()
{
    int hist[5] = { 0 };
    int num_bins = 5;
    int indices[10] = { 0, 0, 2, 3, 3, 3, 3, 4, 4, 4 };
    int num_indices = 10;
    int i;

    for (i = 0; i < num_indices; i++)
    {
        hist[indices[i]]++;
    }
    for (i = 0; i < num_bins; i++)
    {
        printf("%d ", hist[i]);
    }
    printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

假设我有正确的库,这是来自课堂的概念性问题.我想知道阵列的答案如何得出2 0 1 4 3.

c arrays operators

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

汇编二维数组为什么地址没有相同的数字

我在C中创建了一个简单的二维数组,并传递了一个指向汇编函数的指针.我想用汇编函数处理这个数组中的元素.我的问题是我不明白(也许这是我的错误)为什么同一行中元素的地址没有相同的数字.我想处理汇编中的所有元素,但由于地址相差4美元或6美元,我不知道该怎么做.

Adres 1156660110    Adres 1156660114    Adres 1156660120    Adres 1156660124    Adres 1156660130    Adres 1156660134    Adres 1156660140    Adres 1156660144    Adres 1156660150    Adres 1156660154    Adres 1156660160    Adres 1156660164    Adres 1156660170    Adres 1156660174    Adres 1156660200    

Adres 1156660210    Adres 1156660214    Adres 1156660220    Adres 1156660224    Adres 1156660230    Adres 1156660234    Adres 1156660240    Adres 1156660244    Adres 1156660250    Adres 1156660254    Adres 1156660260    Adres 1156660264    Adres 1156660270    Adres 1156660274    Adres 1156660300    

Adres 1156660310    Adres 1156660314    Adres 1156660320    Adres 1156660324    Adres 1156660330    Adres 1156660334    Adres 1156660340    Adres 1156660344    Adres 1156660350    Adres …
Run Code Online (Sandbox Code Playgroud)

c assembly i386

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

以下代码有什么区别?

#include <stdio.h>
#include <stdlib.h>

struct stud
{
    int age;
    struct stud *next;
};

typedef struct stud node;

node *createlist();
void main()
{
    node *head;

    head = createlist();
}

node *createlist()
{

    node *head, *p;

    head = (node *) malloc(sizeof(node));

    int i, n;

    printf("Enter the number of elements\n");
    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        if (i == 0)
        {
            p = head;
        }
        else
        {
            p->next = (node *) malloc(sizeof(node));
            p = p->next;
        }
        p->age = …
Run Code Online (Sandbox Code Playgroud)

c

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

错误是什么:二进制%的无效操作数(具有'float'和'int')意味着什么

#include <stdio.h>

int main(void) 
{
    float with;
    float inacbal;
    float acleft;
    scanf("%f",&with);
    scanf("%f",&inacbal);
    if((with%5)==0)//error here
    {
        acleft=inacbal-with-0.50;
        printf("%f",acleft);
    }
    else
        printf("%f",inacbal);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c

-2
推荐指数
1
解决办法
3万
查看次数

什么是C中的自由指针?

我了解到有两种方法可以在C中声​​明一个数组:

int array[] = {1,2,3};
Run Code Online (Sandbox Code Playgroud)

和:

int* arr = malloc(3*sizeof(int));
Run Code Online (Sandbox Code Playgroud)

为什么arr被称为自由指针?为什么我不能更改数组中包含的地址,而我可以使用数组?

c arrays pointers

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

如何使用查询参数,如强参数?

我如何使用查询参数作为强参数。这是我的 POST /tag 方法,由前端调用以搜索帖子。

def tag
  if params[:category] == 'Shop'
     render json: ShopPostPopulator.new(params[:search]).run
  else
     render json: Part.search(params[:search])
  end
end

Run Code Online (Sandbox Code Playgroud)

如果我想使用强参数而不是 'params[:search]',我该怎么做。

ruby parameters performance ruby-on-rails ruby-on-rails-3

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

C输出因代码不同而不同

#include <stdio.h>
#include <stdlib.h>

int main() {

    int* a[10];
    int* p = a;
    int i = 0;
    for (p = &a[0], i = 0; p < &a[10]; p++, i++)
    {
        *p = i;
    }
    for (int i = 0; i < 10; i++)
    {
        printf("%d\n", a[i]);
    }
}
Run Code Online (Sandbox Code Playgroud)

使用eclipse在GCC上的输出:

0
2
4
6
8
10
12
14
16
18
Run Code Online (Sandbox Code Playgroud)

使用visual studio输出:

0
1
2
3
4
5
6
7
8
9
Run Code Online (Sandbox Code Playgroud)

为什么?

c c++ gcc

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