I'm new to c language. I'm writing a program to insert the number in 2-d array using function and displaying them. my code is following
code:
#include<stdio.h>
void insert(int *a);
void display( int *B)/>;
int main()
{
int b [3][3];
insert(B)/>;
display(B)/>;
return 0;
}
void insert (int *a)
{
int i,j;
for(i=0; i<3; i++)
{
for(j=0;j<3; j++)
{
a[i][j]=5;
}
}
}
void display (int *a)
{
int i,j;
for(i=0; i<3; i++)
{
for(j=0;j<3; j++)
{
printf("%d", a[i][j]);
}
}
}
when i compiled it i got following error:
In function ‘main’:
warning: passing argument 1 of ‘insert’ from incompatible pointer type
note: expected ‘int *’ but argument is of type ‘int (*)[3]’
warning: passing argument 1 of ‘insert’ from incompatible pointer type
note: expected ‘int *’ but argument is of type ‘int (*)[3]’
In function ‘insert’:
error: subscripted value is neither array nor pointer
In function ‘display’:
error: subscripted value is neither array nor pointer
after that i changed the proto type of my insert and display function like
void insert(int **a);
void display(int ** a)
and compile it again than i got following error:
warning: passing argument 1 of ‘insert’ from incompatible pointer type
note: expected ‘int **’ but argument is of type ‘int (*)[3]’
warning: passing argument 1 of ‘insert’ from incompatible pointer type
note: expected ‘int **’ but argument is of type ‘int (*)[3]’
I'm very new to c language can you please answer the following question
1: what are the error suggesting or why I'm getting these error ?
2:what is the proper way to do it ?
3: how can we use single pointer to pass the array to function ?
4 why the double pointer is showing warning ?
5 how we can return array from the function ?
please explain me so that I can get this concept bcoz its a very important concept.
This post has been edited by JackOfAllTrades: 24 March 2012 - 03:05 AM
Reason for edit:: Added code tags

New Topic/Question
Reply



MultiQuote






|