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 3 of 5.

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

Shivangi said:   1 decade ago
If the function would have declared static than it would be correct to pass static parameters inside a function.

Rasu said:   1 decade ago
I am using visual c++, in that I can able to pass static variable as the arguments, it is showing only warning.

Sindhu said:   1 decade ago
Static means those variables are initialized as 0,,so static can never be passed as function arguments...

Tim said:   1 decade ago
This is another C# trick, not ANSI C. No one should use C# unless they want to write non-portable code.

Anonymous said:   1 decade ago
Static variables can not be declared inside method. These are always declared inside the main method.

Shrinivas said:   1 decade ago
Please, Can any one explain what kind of function is this?

int *check(static int i, static int j)

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

Abi said:   1 decade ago
Couldn't understand. Please someone explain clearly. Whats static? why it shouldn't be used?

Sourav pal said:   1 decade ago
Because static variable can not be change, It is initialized at one time. So answer is 1.


Post your comments here:

Your comments will be displayed after verification.