Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program ?

#include <stdio.h>
int *check(static int, static int);

int main()
{
    int *c;
    c = check(10, 20);
    printf("%d\n", c);
    return 0;
}
int *check(static int i, static int j)
{
    int *p, *q;
    p = &i;
    q = &j;
    if(i >= 45)
        return (p);
    else
        return (q);
}

 

  • A.10
  • B.20
  • C.Error: Non portable pointer conversion
  • D.Error: cannot use static for function parameters

Answer: D

Correct answer: Error: cannot use static for function parameters

The only storage class specifier permitted on a function parameter is register. Declaring a parameter static is a constraint violation, and the compiler rejects both the prototype and the definition.

The reason is that a parameter's storage duration is fixed by the call: it comes into existence when the function is entered and vanishes when it returns. static would demand storage lasting the whole program, which is incompatible with being a parameter at all.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.