Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 168 - 170 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 168

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Name the operators that cannot be overloaded.

Explanation

  • Scope Resolution operator (::)
  • Pointer to member operator (. ⚹)
  • Member Access or Dot operator (.)
  • Ternary or Conditional operator (? :)
  • Object size operator (sizeof)
  • Object type operator (typeid)

Question 169

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     externinti;
  4.     i =20;
  5.     printf ( “%d” sizeof (i) );
  6. }

Explanation

  • In a program,
    Table Showing the Program
    extern int i;Extern declaration specifies that the variable i is defined somewhere else.
    i = 20;

    printf ( “% d” sizeof (i) ) ;

    The compiler passes the external variable to be resolved by the linker.

    So compiler doesn՚t find an error.

  • During linking the linker searches for the definition of i.
  • Since it is not found the linker flags an error

Question 170

C & C Plus Plus

Question

MCQ▾

What will be the result of the following program?

  1. char ⚹gxxx ()
  2. {
  3.     staticcharxxx[1024];
  4.     returnxxx;
  5. }
  6. main ()
  7. {
  8.     char ⚹g =“string”;
  9.     strcpy (gxxx (), g);
  10.     g =gxxx ();
  11.     strcpy (g, “oldstring” );
  12.     printf ( “Thestringis:%s” gxxx () );
  13. }

Choices

Choice (4)

a.

Run time error/Core dump

b.

The string is: Oldstring

c.

Syntax error during compilation

d.

The string is: String

Answer

b.

Explanation

  • In the program
Table Showing the Program
  1. char ⚹gxxx ()
  2. {
  3.     staticcharxxx[1024];
  4.     returnxxx;
  5. }
  • Define the pointer function gxxx ()
char ⚹ g = “string” ;
  • Define the character pointer g = “string”
strcpy (gxxx () , g) ;
  • Here using the strcpy () function char ⚹ strcpy (char ⚹ dest, const char ⚹ src) copies the string pointed to, by “src” to dest.
g = gxxx () ;
  • pointer g value stores the output of gxxx () function
strcpy (g, “oldstring” ) ;
  • pointer g stores the string
printf ( “The string is:% s” gxxx () ) ;
  • printf prints “The string is: Oldstring”

Developed by: