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;
}
Discussion:
6 comments Page 1 of 1.
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
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)
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?
So (*ptr)(x) = (*ptr)(30).
So x = 30;
In the same way 30 = x;
How is the answer?
(1)
Akshay said:
1 decade ago
What's the use of (*ptr)(3) = (*ptr)(x)?
Supi said:
10 years ago
Please explain the try-run of the program.
Krishnan said:
9 years ago
Thanks @Nivetha.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers