3i Infotech Papers: Sample Questions 152 - 153 of 1245

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 152

» Languages » C & C Plus Plus

Short Answer Question▾

Write in Short

Differentiate between the message and method.

Explanation

Differentiate between the message and method.

Differentiate between the message and method.

Message

Method

Objects communicate by sending messages to each other.

Provides response to a message.

A message is sent to invoke a method.

It is an implementation of an operation.

Message refers to instruction sent to object which will invoke the related method.

Method is a function or procedure that is defined for a class and typically can access the internal state of an object of that class to perform some operation.

A message is any packet of communication between objects. The objects may be in the same program, or they may be on different systems. It simply doesn’t matter.

A method is a block of code attached to an object by some means. It may be implicitly attached by means of a class, or it may be an anonymous closure attached to an arbitrary attribute of the object.

Question number: 153

» Languages » C & C Plus Plus

Short Answer Question▾

Write in Short

  1. main ()
  2. {
  3.     int i = 5;
  4.     printf ( “%d%d%d%d%d%d” i + +, i--, + + i, -ii);
  5. }

Explanation

  • The evaluation is by popping out from the stack.

Table shows the program

Table shows the program

int i = 5;

Here define the integer variable i = 5

printf (“%d % d%d % d%d % d” i ++, i–, ++ i, -i, i);

Print the all values of i

The arguments in a function call are pushed into the stack from left to right.

First value in stack top to bottom is i

i = 5

Second value in stack is -i

-i = 4

Third value in stack is ++i

++i = 5

Fourth value in stack is i–

i–=5

Fifth value in stack is i++

i++=4

  • And the evaluation is from right to left

  • So the answer is 45545.