c - 出现错误 : expression not assignable

标签 c

我是 C 新手,我找不到任何关于为什么它给我一个错误的答案:第 11 行和第 20 行表达式不可分配

这是一个简单的代码,用于创建随机数组,然后使用子例程对其进行排序。我仍在学习 C,并且无法通过任何研究找到解决方案。

这是我的代码:

#include <stdio.h>
#include <stdlib.h>
int myArray[100];
int* ptr = myArray;
int i;
int n = sizeof(myArray);
int SortedArray[100];

int MakeRandArray(ptr, i)
{
    for (i = 0; i < n; i++) {
        (ptr + i) = rand()
    }
}

int SortArray(ptr)
{
    int a;
    int j = (i + 1);
    for (i = 0; i < n; i++) {
        if ((ptr + i) > (ptr + j)) {
            (ptr + i) = (ptr + j)
        }
    }
}

int main()
{
    MakeRandArray(*ptr, i);
    SortArray(*ptr);
}

最佳答案

您没有正确取消引用指针。

第 11 行:

ptr[i] = rand();

第 20 行:

if (ptr[i] > ptr[j]){
    ptr[i] = ptr[j];
}

或者,您可以指定 *(ptr + i) 来获取 ptr[i] 处的值。

关于c - 出现错误 : expression not assignable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44377418/

相关文章:

c - 将 sqlite3_column_text() 返回到文字字符串

c - 使用 gcc 在共享库中传播 "-g"

C fscanf 丢弃多余的字符(如果有的话)

c - Visual Studio 2012 : LNK2028 and LNK2019 build errors

检查回文

c - 用C发送ARP包

c - 为什么 rand() + rand() 产生负数?

c - 在 Kill() 中实现 EINVAL、EPERM、ESRCH

c - 将文本文件的每一行转换为数组 c

c - nginx 内存池损坏?