C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 5)
5.
What will be the output of the following program?
#include<iostream.h> 
typedef void(*FunPtr)(int);
int Look(int = 10, int = 20);
void Note(int); 
int main()
{
    FunPtr ptr = Note;
    (*ptr)(30); 
    return 0;
}
int Look(int x, int y)
{
    return(x + y % 20);
}
void Note(int x)
{
    cout<< Look(x) << endl;
}
10
20
30
40
Compilation fails.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
6 comments Page 1 of 1.

Krishnan said:   9 years ago
Thanks @Nivetha.

Venki said:   10 years ago
(*ptr)(30) = (*ptr)(x).

So (*ptr)(x) = (*ptr)(30).

So x = 30;

In the same way 30 = x;

How is the answer?
(1)

Supi said:   10 years ago
Please explain the try-run of the program.

Akshay said:   1 decade ago
What's the use of (*ptr)(3) = (*ptr)(x)?

Nivetha said:   1 decade ago
(*ptr)(30) = (*ptr)(x)
So x = 30;
Look(30,20) = 30+20%20 here %have higher precedence.
So 30+(20%20) = 30+0 = 30
(5)

Isha said:   1 decade ago
How is the answer? 30 please explain.
(1)

Post your comments here:

Your comments will be displayed after verification.