【问题标题】:Deleting a struct instance删除结构实例
【发布时间】:2021-12-04 15:46:10
【问题描述】:
{
    int degree;
    double *coeff; 
};

struct poly create_poly()
{// Ask the user to enter the degree of the polynomial and (degree +1) coefficients
    struct poly p;
    printf("Power of the polynomial : ");
    scanf("%d", &p.degree);
    p.coeff = malloc((p.degree + 1) * sizeof *p.coeff);
    for (int i = 0; i <= p.degree; i++)
    {// Read a double as coeff
        printf("Enter the coeff x^%d : ", i);
        scanf("%lf", &p.coeff[i]);
    }
    return p;
}

int main{
 struct poly p1 = create_poly();
 struct poly p2 = create_poly();
struct poly p3 = create_poly();
}

假设我有一个看起来像struct poly 的结构。我有一个创建结构实例的函数,即create_poly。主函数是该函数用于创建实例的地方。假设我想删除实例 p2。我该如何继续呢? 谢谢你

【问题讨论】:

    标签: c


    【解决方案1】:

    我认为以下链接中给出的解释可以回答您的问题: Deleting all structure entries in C Programming

    Delete struct from stack memory

    【讨论】:

    • 请在下次分享的资源中提供相关部分的报价。这样,没有经验的用户可以更轻松地找到自己的方式。
    • @Meto 你是对的。谢谢你让我知道。下次我会做的。只是表示在这两个链接中,我发现上述问题的答案不止一个。
    猜你喜欢
    • 1970-01-01
    • 2022-07-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 2012-10-26
    • 1970-01-01
    • 2020-09-14
    • 2016-03-12
    相关资源
    最近更新 更多