code break wrote:
Can Any one tell me why this program is crashing .
What program. I can't see a program in your post; all I see is a
function.
testFunc()
int testFunc(void)
or
int testFunc(...) /* this looks strange. I have to review variable
argument list material */
I prefer to specify return type and parameters explicitly rather than
relying on the defaults.
{
int a1[10], *ptr ;
f=&a1[0];
There's no scope for `f' at this point (unless it's a global variable).
Assuming it's been declared as int* or void*, I'd write that as
f = a1;
because the name of an array specifies the address of its first element,
and, for a simple assignment to a pointer the redundant "&" and "[0]"
actally make it less legible for me.
f=f+1;
return 0;
ptr has been declared but has never been used. Delete its declaration.
}
If you really have this function in some code of yours, as what it
really does is just return 0 to the caller, I think you could make your
program much simpler by removing the function and replacing it with a
constant zero instead;
Example (where foo has been defined as a int):
if (foo == testFunc()) { /* do something */ }
/* replace last line with */
if (foo == 0) { /* do something */ }
--
If you're posting through Google read <http://cfaj.freeshell.org/google>