C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 8)
8.
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);
}
10
20
Error: Non portable pointer conversion
Error: cannot use static for function parameters
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
50 comments Page 4 of 5.

Mani said:   1 decade ago
Static member function cannot access the non static members.

Apurva Nigam said:   1 decade ago
@Mani:
Here the function is NON STATIC. so does it mean it cant access static variables???

What if both(ie parameters and function) were static??
Then the code would be correct??
Or
@Nikhil:
u mean Parameters can never be static whether its a STATIC or NON STATIC function???

Ramesh said:   1 decade ago
@apurva nigam.

Remember that, like any other local variable, a static variable cannot be referred to outside the function.

Gopi said:   1 decade ago
Static variables will never change its value but parameters used in function should suppose to have different values.

Sarang S. Metkar said:   1 decade ago
Can anyone tell me what is d meanining of "timid" ?

Rajsekhar said:   1 decade ago
It gives an error:.

Storage class specified for parameter i, j;.

Because we can not pass static variables to the functions.

Rocky said:   1 decade ago
Line 13: error: storage class specified for parameter 'type name'
Line 13: error: storage class specified for parameter 'type name'
Line 22: error: storage class specified for parameter 'i'
Line 22: error: storage class specified for parameter 'j'

Manish said:   1 decade ago
While executing getting following error.

p15.c:2: error: storage class specified for parameter 'type name'
p15.c:2: error: storage class specified for parameter 'type name'
p15.c: In function 'main':
p15.c:8: warning: format '%d' expects type 'int', but argument 2 has type 'int *'
p15.c: At top level:
p15.c:11: error: storage class specified for parameter 'i'
p15.c:11: error: storage class specified for parameter 'j'

Sachin said:   1 decade ago
Can any one explain this one please?

Venky498 said:   1 decade ago
Hi friends,

According to ANSI C standards we can not pass the variables which are declared as storage class type to function as aruguments except register storage class variables but in the above program even register is also not works...why bcoz at the LINE:14 we are trying to access the address of register.


Post your comments here:

Your comments will be displayed after verification.