Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Test Questions

Posted on 2006-05-08
Medium Priority
Last Modified: 2009-08-26
These are the test questions I had in my written test.
1.      memset is sometimes used to initialize data in a constructor like the example below. What is the benefit of initializing this way?  Does it work in this example?  Does it work in general ? Is it a good idea in general?

      class A {
         int a;
         float f;
         char str[35];
         long *lp;

         memset(this, 0, sizeof(*this));

2.      You have a class that many libraries depend on. Now you need to modify the class for one application. Which of the following changes require recompiling all libraries before it is safe to build the application?

         a.  add a constructor
         b. add a data member
         c. change destructor into virtual
         d. add an argument with default value to an existing member function

Question by:koppcha
  • 2
LVL 86

Expert Comment

ID: 16636069

>>What is the benefit of initializing this way?

You will avoid errors that could result in a random memory state
>>Does it work in this example?

memset(this, 0, sizeof(*this));

will defintely work for the purpose of setting that class' members to zero.

>>Does it work in general ?

Yes. If the defaults the variables are set to are handled correctly by the code tha deals with them.

>>Is it a good idea in general?

Initializing variables or memory in general is always a good idea, since odd things can happen if you get to use a randomly initialized value, NULLing data is a good choice for sure.
LVL 86

Accepted Solution

jkr earned 1000 total points
ID: 16636080
Oh, I forgot about


All of them.

Author Comment

ID: 16636317
Thanks jkr

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question