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

Write in Short Short Answer▾

Name the operators that cannot be overloaded.

Edit

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

Describe in Detail Essay▾

  1. main ()
  2. {
  3. extern int i;
  4. i =20;
  5. printf ( “%d sizeof (i) );
  6. }
Edit

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

Question MCQ▾

What will be the result of the following program?

  1. char gxxx ()
  2. {
  3. static char xxx[1024];
  4. return xxx;
  5. }
  6. main ()
  7. {
  8. char g =“string”;
  9. strcpy (gxxx (), g);
  10. g =gxxx ();
  11. strcpy (g, “oldstring” );
  12. printf ( “The string is:%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

Edit

Answer

b.

Explanation

  • In the program
Table Showing the Program
  1. char gxxx ()
  2. {
  3. static char xxx[1024];
  4. return xxx;
  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”