C++ Programming - Functions - Discussion

Discussion Forum : Functions - Programs (Q.No. 21)
21.
What will be the output of the following program?
#include<iostream.h> 
class IndiaBix
{
    int K; 
    public:
    void BixFunction(float, int , char);
    void BixFunction(float, char, char);
    
};
int main()
{
    IndiaBix objIB;
    objIB.BixFunction(15.09, 'A', char('A' + 'A'));
    return 0;
}
void IndiaBix::BixFunction(float, char y, char z)
{
    K = int(z);
    K = int(y);
    K = y + z;
    cout<< "K = " << K << endl; 
}
The program will print the output M = 130.
The program will print the output M = 195.
The program will print the output M = -21.
The program will print the output M = -61.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 1 of 2.

AKS said:   1 decade ago
char('A'+'A') is 65+65=130 which is out the signed range of char i.e., -128 to 127

So, -128+(130-128)= -126 = z
Therefore,
K = y + z = 65 + -126 = -61
(4)

Arpan said:   5 years ago
K is initialized within a class without access specifier, so by default it will be private. How they are able to use K outside the class?
(1)

Rakesh said:   1 decade ago
How this work please explain me?

Shiksha said:   1 decade ago
A single definition for two declarations isn't an issue here!

Why so?

Anonymous said:   1 decade ago
Yes no issue.

If there would be a function call to the function which is only declared but not defined, then while checking the compiler would have been given a compile time error that the function is not defined.

And by the way here there is not a single definition for two declarations, rather the definition is specified only for the one function i.e.

void BixFunction(float, char, char);

Sai theja said:   8 years ago
@Aks.

Why A value is taken as 65?

Nam said:   8 years ago
The char type can be both signed (from -128 to 127) or unsigned (0 to 255), it is depended on the concrete C++ implementation. So the answer -61 is not always true.

See "The C++ Programming Language, 4th edition" by Bjarne Stroustrup, section 6.2.3.

Anonymous said:   8 years ago
There is no variable name for float in member function definition.

Anonymous said:   8 years ago
This is BS question! Why you are supposed to remember ASCII table and exact value of signed char?

Max said:   8 years ago
@ALL.

cout<< "K = " << K << endl; so it will 100% print "K = ", wtf is answer "M = "?


Post your comments here:

Your comments will be displayed after verification.