3i Infotech Papers: Sample Questions 429 - 430 of 1245

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 429

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is a Null object?

Explanation

  • An object of some class whose purpose is to indicate that a real object of that class does not exist.

  • One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.

  • In object-oriented computer programming, a Null Object is an object with no referenced value or with defined neutral behavior.

  • The Null Object design pattern describes the uses of such objects and their behavior (or lack thereof).

Image of the Null object

Image of the Null Object

Define the null object synopsis, context and forces

Question number: 430

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is the output of the following program?

  1. void main()
  2. {
  3.     int *mptr,*cptr;
  4.     mptr=(int*)malloc(sizeof(int));
  5.     printf(“%d ”,*mptr );
  6.     cptr=(int*)calloc(sizeof(int),1);
  7.     printf(“%d”,*cptr);
  8. }

Explanation

In the program

Table shows the program

Table shows the program

int * mptr, *cptr;

  • Given the integer pointer mptr and cptr.

mptr= (int*) malloc (sizeof (int) );

printf (“%d “, *mptr);

  • The memory space allocated by malloc is uninitialized.

  • So it will print garbage value.

cptr= (int*) calloc (sizeof (int), 1);

printf (“%d”, *cptr);

  • Calloc initializes the allocated memory space to zero.

 Malloc and Calloc

Malloc and Calloc

Define the calloc and malloc function.