C Programming - Functions - Discussion

Discussion Forum : Functions - Find Output of Program (Q.No. 16)
16.
What will be the output of the program?
#include<stdio.h>
int check(int);
int main()
{
    int i=45, c;
    c = check(i);
    printf("%d\n", c);
    return 0;
}
int check(int ch)
{
    if(ch >= 45)
        return 100;
    else
        return 10;
}
100
10
1
0
Answer: Option
Explanation:

Step 1: int check(int); This prototype tells the compiler that the function check() accepts one integer parameter and returns an integer value.

Step 2: int l=45, c; The variable i and c are declared as an integer type and i is initialized to 45.

The function check(i) return 100 if the given value of variable i is >=(greater than or equal to) 45, else it will return 10.

Step 3: c = check(i); becomes c = check(45); The function check() return 100 and it get stored in the variable c.(c = 100)

Step 4: printf("%d\n", c); It prints the value of variable c.

Hence the output of the program is '100'.

Discussion:
3 comments Page 1 of 1.

Pavan said:   7 years ago
Here, >= means 45>=45 =true that's why 100.

Mamatha said:   7 years ago
Here, what is the value of ch?

Ashutosh dubey said:   9 years ago
In my opinion, ch is int type and 45 must be long int type so ch >45 is false.

Post your comments here:

Your comments will be displayed after verification.