About Use Of Storage Classes in C -
the following code displays error if storage class of parameters of function int *check(register int,register int);
declared other storage class.
i compiled code on code::blocks 10.05 ide gnu gcc compiler. reason behind error? compiler specific error or general one? code section begins here:
int *check(register int, register int); int main() { int *c; c = check(10, 20); printf("%d\n", c); return 0; } int *check(register int i,register int j) { int *p = i; int *q = j; if(i >= 45) return (p); else return (q); }
int *check(register int i,register int j) { int *p=i; int *q=j; if(i >= 45) return (p); else return (q); }
while register
storage class specifier allowed on parameter declaration, parameters i
, j
have int
type while p
, q
of type int *
. makes declaration of p
, q
invalid.
you cannot change to:
int *p=&i; int *q=&j;
as &
operator not allow have operand of register
storage class.
you cannot also change parameter declaration register int i
, register int j
int i
, int j
, return address of i
, j
object lifetime ends @ exit of function.
in case should not use pointers: use int
parameters , int
return value.
Comments
Post a Comment