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

C & C Plus Plus
Edit

Write in Short

Short Answer▾

How can a ‘::’ operator be used as unary operator?

Explanation

  • The scope operator can be used to refer to members of the global namespace.
  • Because the global namespace doesn՚t have a name, the notation:: member-name refers to a member of the global namespace.
  • Useful for referring global namespace members whose names are hidden by names declared in nested local scope.
  • Unless we specify to the compiler in which namespace to search for a declaration, the compiler simple searches the current scope, and any scopes in which the current scope is nested, to find the declaration for the name.
Given the Image is Scope Operator be Used as Unary Operator

Question 300

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Predict the output or error (s) for the following:

  1. main ()
  2. {
  3.     inta =10, ⚹j;
  4.     void ⚹k;
  5.     j =k =&a;
  6.     j ++;
  7.     k ++;
  8.     printf ( “ %u %u”, j, k);
  9. }

Explanation

  • In the program
Table Showing the Program
int a = 10, ⚹ j;
  • Define the integer variable a = 10 and pointer j
void ⚹ k;
  • Define the void pointer k
j = k = &a;
  • Address of a is stored in j and k
j ++ ;
  • Increment the j value.
k ++ ;
  • Increment the k value
  • But void pointers are generic and are used only when the type is not known and as an intermediate address storage type.
  • No pointer arithmetic can be done on them and program cannot apply indirection operator (⚹) on void pointers.

Developed by: