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

Describe in Detail Essay▾

What is name mangling?

Edit

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

Write in Short Short Answer▾

What is alloca ()

Edit

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. int open2 (char str1, char str2, int flags, int mode)
  2. {
  3. char name =(char ⚹) alloca (strlen (str1) +strlen (str2) +1);
  4. stpcpy (stpcpy (name, str1), str2);
  5. return open (name, flags, mode);
  6. }