closed by
732 views
0 votes
0 votes
closed with the note: Error
what is wrong with this code? It shows segmentation fault

#include<stdio.h>
#include<stdlib.h>
void main()
{
    int i,j,count=1;
    int **a=(int**)malloc(3*sizeof(int*));
    for(i=0; i<3; i++)
    {
        a[i]=(int*)malloc(4*sizeof(int));
    }
    for(i=0; i<3; i++)
    {
        for(j=0; j<4; j++)
        {
            a[i][j]=count; count++;
        }
    }
    printf("\n");
    for(i=0; i<3; i++)
    {
        for(j=0; j<4; j++)
        {
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }
}
closed by

1 Answer

0 votes
0 votes
instead of writing of void main() plz write the int main();

Related questions

4 votes
4 votes
1 answer
1
4 votes
4 votes
2 answers
2
sh!va asked Jul 16, 2016
1,229 views
In C/C++ an array of pointers is same as(A) Pointer to array(B) Pointer to pointer(C) Pointer to function (D) Pointer to structure
0 votes
0 votes
2 answers
3
vishalmessi asked Dec 11, 2016
4,032 views
#include <stdio.h int main() { int a[][3] = {1, 2, 3, 4, 5, 6}; int (*ptr)[3] = a; printf("%d %d ", (*ptr) , (*ptr) ); ++ptr; printf("%d %d\n", (*ptr) , (*ptr) ); return ...