C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 4)
4.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
static int b = 0; 
void DisplayData(int *x, int *y = &b)
{
    cout<< *x << " " << *y;
}
int main()
{
    int a = 10, b = 20 ;
    DisplayData(&a, &b);
    return 0; 
}
The program will print the output 10 20.
The program will print the output 10 0.
The program will print the output 10 garbage.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
10 comments Page 1 of 1.

Rohitash said:   8 years ago
The static variable initial value only one time assigned in a program. Why here assign two times, b=0, b=20?

Mounika said:   1 decade ago
Here b variable is globally declared as static, is it possible to change value of b in main function.

Shreyas said:   1 decade ago
Default argument will not work, as we are passing value from function Display Data.

Anonymous said:   1 decade ago
Yes, value of a static variable can be changed, but their address never changes.

Shivang said:   5 years ago
It uses call by reference so the value of the main function will be the answer.

Rohullah tofan said:   9 years ago
Is anyone knows the correct answer?

Pooja said:   8 years ago
A is the correct answer. I agree.

Vishal said:   1 decade ago
But what is the correct answer?

Anonymous said:   10 years ago
Is the given answer correct?

Sahil said:   9 years ago
I think it should be 10 0.

Post your comments here:

Your comments will be displayed after verification.