© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

4. Differentiate between the message and method.

Ans:
          Message                                                                   Method
Objects communicate by sending messages     Provides response to a message.
to each other.

A message is sent to invoke a method.             It is an implementation of an operation.

Ex - 1: What is the output?

void main()
{
            int k=ret(sizeof(float));
            printf("\n here value is %d",++k);
}
int ret(int ret)
{
            ret += 2.5;
            return(ret);
}

Ans:
Here value is 7

Explanation:

The int ret(int ret), ie., the function name and the argument name can be the same.
            Firstly, the function ret() is called in which the sizeof(float) ie., 4 is passed,  after the first expression the value in ret will be 6, as ret is integer hence the value stored in ret will have implicit type conversion from float to int. The ret is returned in main() it is printed after and preincrement.

Ex - 2: What is the output?.

void main()
{
            char a[]="12345\0";
            int i=strlen(a);
            printf("here in 3 %d\n",++i);
}

Ans:
here in 3 6

Explanation:

The char array 'a' will hold the initialized string, whose length will be counted from 0 till the null character. Hence the 'I' will hold the value equal to 5, after the pre-increment in the printf statement, the 6 will be printed.


SLogix Student Projects
bottom