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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is name mangling?

Explanation

  • Name mangling in c ++ compilers gives each function a unique name.
  • This is required in C ++ , all programs have a few functions with the same name. Name mangling allows linker to link to function names which are unique.
  • Example: In general, member names are made unique by concatenating the name of the member with that of the class e. g. given the declaration: class Bar {public: int ival; …} ; ival becomes something like: // a possible member name manglingival________3BarConsider this derivation: class Foo: public Bar {public: int ival; …}
  • The internal representation of a Foo object is the concatenation of its base and derived class members. // Pseudo C ++ code // Internal representation of Foo class Foo {public: int ival________3Bar; int ival________3Foo; …} ;
  • Thus, unambiguous access of either ival members is achieved through name mangling.
  • Member functions, because of overloading, require extensive mangling for unique names based on argument.

Question 341

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is alloca ()

Explanation

  • It allocates and frees memory after use or after getting out of scope.
  • As an example of the use of alloca, here is a function that opens a file name made from concatenating two argument strings, and returns a file descriptor or minus one signifying failure:
  1. intopen2 (char ⚹str1, char ⚹str2, intflags, intmode)
  2. {
  3.     char ⚹name =(char ⚹) alloca (strlen (str1) +strlen (str2) +1);
  4.     stpcpy (stpcpy (name, str1), str2);
  5.     returnopen (name, flags, mode);
  6. }

Developed by: