[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Technical Discussion :: C++

55 / 187

What is Namespace?

Answer:

Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say it somehow, they serve to split the global scope in sub-scopes known
as namespaces.The form to use namespaces is:

namespace identifier { namespace-body }

Where identifier is any valid identifier and namespace-body is the set of classes, objects and functions that are included within the namespace. For example:
namespace general { int a, b; } In this case, a and b are normal variables integrated within the general namespace. In order to access to these variables from outside the namespace we have to use the scope operator ::. For example, to access the previous variables we would have to put:

general::a general::b

The functionality of namespaces is specially useful in case that there is a possibility that a global object or function can have the same name than another one, causing a
redefinition error.

Asked In ::

Post Your Answer Here:


Rate This: +1 -0      +
Report    

Post Your Reply Here:

Alert me
q4i-reply-your-answer

Report Error

Please Login First Click Here

Most Popular Qs.