N
Nosophorus
Hi! 
I was coding a trivial problem concerning static variables and
pointers intended to scan/read an array, when I took a hint in another
code. So, an excerpt of the final version of my code is:
int func1(int *a = 0)
{
static int *p;
if(a) //<--*THIS LINE*
{
p = a;
return(*p);
}
else
if(*p != -1)
{
p = p + 1;
return(*p);
}
else
return(0);
}
The function "func1" takes a pointer (named "a") to an int and the
default value of that pointer is zero. What interests me is the
meaning of the line "if(a)".
What I know is that if a parameter is passed to the function "func1",
then the "if(a)" is triggered and all the lines inside its scope are
run. BUT, I do not know what kind of result is given by that line
( the "if(a)" ). It's a logical one (TRUE, FALSE)? Does a pointer have
a logical value or something else in a situation like that?
It seems strange to me that a pointer without the dereference operator
can be used in an "if" statement. :-/
I appreciate any explanation and further help.
Thank You!
Marcelo de Brito
I was coding a trivial problem concerning static variables and
pointers intended to scan/read an array, when I took a hint in another
code. So, an excerpt of the final version of my code is:
int func1(int *a = 0)
{
static int *p;
if(a) //<--*THIS LINE*
{
p = a;
return(*p);
}
else
if(*p != -1)
{
p = p + 1;
return(*p);
}
else
return(0);
}
The function "func1" takes a pointer (named "a") to an int and the
default value of that pointer is zero. What interests me is the
meaning of the line "if(a)".
What I know is that if a parameter is passed to the function "func1",
then the "if(a)" is triggered and all the lines inside its scope are
run. BUT, I do not know what kind of result is given by that line
( the "if(a)" ). It's a logical one (TRUE, FALSE)? Does a pointer have
a logical value or something else in a situation like that?
It seems strange to me that a pointer without the dereference operator
can be used in an "if" statement. :-/
I appreciate any explanation and further help.
Thank You!
Marcelo de Brito