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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -