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.

Sucharita said:   1 decade ago
We can use static data member but for that the function should be static itself. (C++ concept).

Sumit said:   1 decade ago
Static member is initialized to 0 so can't be passed as arguments.

Xstream said:   1 decade ago
Static members are cannot be used as arguments in a function its a general rule.

Kingalbert4m said:   1 decade ago
Static member function cann't access the non static members.

Mekalacheruvu purushotham said:   1 decade ago
It is a function which returns integer pointer.

Barath said:   1 decade ago
Acc to ANSI C standards we can not pass variables which are specified with storage class to function as arguments except the variables with the keyword register.

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.

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'

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'

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.


Post your comments here:

Your comments will be displayed after verification.