void main()
{
int a=10;
int *j;
*j=&a;
b[]={1,2,3,4};
b=j;
}
Some one asked me is there any problem in this program ,i am just confused for me everything seems fine. Just curious to know.
void main()
{
int a=10;
int *j;
*j=&a;
b[]={1,2,3,4};
b=j;
}
Some one asked me is there any problem in this program ,i am just confused for me everything seems fine. Just curious to know.
Turn on all your compiler warnings and errors. Then it will tell you exactly what is wrong with the program.
*j = &a;
is a constraint violation. *j
has type int
but &a
has type int *
which is incompatible.
You might have meant j = &a;
which will point j
to a
.
b[]={1,2,3,4};
is a syntax error. Maybe you meant int b[]={1,2,3,4};
which would declare an array.
b=j;
is a constraint violation because b
is an array and arrays cannot be assigned to. (Technically: because b
is an array, decays to an rvalue and rvalues cannot be assigned to).
However, j = b;
would be OK and it would make j
point to the first member of b
;
void main()
is non-portable, it should be int main()
.