首页 > 解决方案 > 为什么我无法在这个问题中打印长度值?

问题描述

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

struct rect
{
   int length;
   int breadth;
};

void initialize(struct rect *r,int l , int b)
{
    r->length=l;
    r->breadth=b;
}

void changelength(struct rect *r,int l)
{
    r->length=l;
}

int area(struct rect r)
{
    return(r.length*r.breadth);
}

int main()
{
    struct rect r;
    initialize(&r,10,5);
    changelength(&r,3);
    area(r);
    printf("The rectangle is %d and %d\n",initialize);
    printf("The length is %d\n",changelength);
    printf("The area is %d",area(r));
    return 0;
}

标签: c++

解决方案


你似乎想要的是这样的:

struct rect r;

initialize(&r, 10, 5);
printf("The rectangle is %d and %d\n", r.length, r.breadth);

changelength(&r, 3);
printf("The length is %d\n", r.length);

printf("The area is %d\n", area(r));

推荐阅读