What is wrong with this code in C programming language?

时间:2017-04-06 16:53:17

标签: c arrays pointers

When compiled no compilation errors but force closes when taken input. Do i have to use double pointer? help me out please. Thank you

#include <stdio.h>

void main() {
    int *a;
    allocate(a);
    input(a);
    display(a);
}
void allocate(int *a){
    a = malloc(sizeof(int)*3);
}

void input(int *a){
    int i=0;
    for(;i<3;i++){
    scanf("%d",&a[i]);
    }
}
void display(int *a){
    int i=0;
    for(; i<3;i++){
        printf("%d",a[i]);
    }
}

0 个答案:

没有答案