Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 329 - 331 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 329

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Why are function arguments called “signatures” ?

Explanation

  • The arguments distinguish functions with the same name (functional polymorphism) .
  • The name alone does not necessarily identify a unique function but name and arguments (signatures) uniquely identify a function.
  • For ex: class person {public: char getsex () ; void setsex (char) ; void setsex (int) ;} ;
  • Functions setsex () have same name but different signature.

Question 330

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What do you mean by friendly in C ++ ?

Explanation

  • A friend function of a class is defined in class scope but it has the right to access all private and protected members of another class.
  • The proper types for friend functions appear in the class definition, friends are not member function.
  • A friend can be a function, function template, or member function. If a class or class template is member, than entire class and all of its members are friends.

Below is declaration of a friend function:

class Box {

double width;

public:

double length;

friend void printWidth (Box box) ;

void setWidth (double wid) ;

} ;

Question 331

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. voidpascalf (inti, intj, intk)
  2. {
  3.     printf (%d %d %d, i, j, k);
  4. }
  5. voidcdeclf (inti, intj, intk)
  6. {
  7.     printf (%d %d %d, i, j, k);
  8. }
  9. main () {
  10.     inti =10;
  11.     f (i ++, i ++, i ++ );
  12.     printf( “%d” i);
  13.     i =10;
  14.     f (i ++, i ++, i ++ );
  15.     printf( “%d” i);
  16. }

Explanation

In the program

Table Shows the Program
int i = 10;
  • Declare the integer variable i = 10
f (i ++ , i ++ , i ++) ;

printf ( “% d” i) ;

  • Pascal Function declaration and print the value of i
i = 10;

f (i ++ , i ++ , i ++) ;

printf ( “% d” i) ;

  • Cdecl function declaration and print the value of i
void pascal f (int i, int j, int k)

{

printf (% d % d % d, i, j, k) ;

}

  • Pascal arguments passing mechanism forces the arguments to be called from left to right.
void cdecl f (int i, int j, int k)

{

printf (% d % d % d, i, j, k) ;

}

  • cdecl is the normal C arguments passing mechanism where the arguments are passed from right to left.

Developed by: