C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 15)
15.
Which of the following statement is correct about the program given below?
#include<iostream.h>
struct MyStructure
{
class MyClass
{
public:
void Display(int x, float y = 97.50, char ch = 'a')
{
cout<< x << " " << y << " " << ch;
}
}Cls;
}Struc;
int main()
{
Struc.Cls.Display(12, 'b');
return 0;
}
Discussion:
10 comments Page 1 of 1.
Ashwak said:
1 decade ago
Here, x=12,
y=98 (ASCII value of 'b' will be assigned to y).
ch=a (default).
Hence the output 12,98,a
y=98 (ASCII value of 'b' will be assigned to y).
ch=a (default).
Hence the output 12,98,a
Pankaj bharambe said:
1 decade ago
But how do we know ASCII value of b?
Dinesh said:
1 decade ago
Here char 'a' will replaced by char 'b'. But the result is char 'a' why? Please clarify.
Rohit said:
1 decade ago
Why y value is 98 not 98.00? Please explain.
Pushpa said:
1 decade ago
Sorry @Dinesh you misunderstood the concept.
Actually, x value passed in parentheses as 12, y value given as a character that is 'b'. Float will accept only real no.
So its converted 'b' as a float, b's ASCII value is 98. So it showing 98. And third one is character, 'a' already assigned as default value in function definition itself. So its take directly.
Actually, x value passed in parentheses as 12, y value given as a character that is 'b'. Float will accept only real no.
So its converted 'b' as a float, b's ASCII value is 98. So it showing 98. And third one is character, 'a' already assigned as default value in function definition itself. So its take directly.
Anshuman said:
10 years ago
How come b = 97!?
Please explain?
Please explain?
Abhinav said:
9 years ago
Why Y value is 98 not 98.of? Please explain.
Ashutosh said:
8 years ago
But why they didn't consider y as it is 97.50 and char a instead of char b?
Both y and ch are the default.
Both y and ch are the default.
Mayuresh Bhola said:
8 years ago
When the function can accept a character argument then why it will print ASCII value of b it can accept b as a character isn't it?
Saiyan said:
7 years ago
@Mayuresh Bhol.
In this case the value "b" was accepted by float, not by char. Value "b" has an ascii value of 98. Char didn't get anything, so it printed "a".
In this case the value "b" was accepted by float, not by char. Value "b" has an ascii value of 98. Char didn't get anything, so it printed "a".
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers