Languages-C & C Plus Plus [TCS Placement]: Sample Questions 45 - 46 of 119

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 45

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is null pointer?

Explanation

  • There are times when its necessary to have a pointer that doesn՚t point to anything- Null pointer is this special reserved value of pointer.
  • The macro NULL has a value that՚s guaranteed to be different from any valid pointer.
  • NULL is a literal zero, possibly cast to void ⚹ or char ⚹ .
  • Some people, notably C ++ programmers, prefer to use 0 rather than NULL. The null pointer is used in three ways: 1) To stop indirection in a recursive data structure. 2) As an error value. 3) As a sentinel value.
  • Example:
  1. #include<stdio.h>
  2. intmain()
  3. {
  4.     int ⚹ptr=NULL;
  5.     printf(“Thevalueofptris %u”,ptr);
  6.     return0;
  7. }

Output:

The value of ptr is 0

Question 46

C & C Plus Plus

Question

MCQ▾

Which of the following concepts means wrapping up of data and functions together?

Choices

Choice (4)

a.

Polymorphism

b.

Abstraction

c.

Inheritance

d.

Encapsulation

Answer

d.

Explanation

  • Encapsulation is wrapping up of data and functions together- class in C ++ is the wrapper.
  • Encapsulation thus encloses function and members within classes. Objects contain these attributes and the methods.
  • Data and functions thus form a single unit.
Given the Image is Define the Encapsulation

Developed by: