Languages [TCS Placement]: Sample Questions 119 - 120 of 131

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 119

Edit

Describe in Detail

Essay▾

Which function in C can be used to append a string to another string?

Explanation

  • The strcat () function- takes two parameters, the source string and the string value to be appended to the source string.
  • A copy of the second string is tacked onto the end of the first, and this combined version becomes the new first string.
  • The second string is not altered.
  • It returns the value in its first argument.
  • Example:
  1. #include<stdio.h>
  2. #include<string.h>
  3. intmain()
  4. {
  5.     charsrc[50], dest[50];
  6.     strcpy(src, “ Goenka”);
  7.     strcpy(dest, “Kartik”);
  8.     strcat(dest,src);
  9.     printf(“Myname :%s ”,dest);
  10.     return0;
  11. }

Output:

My name: Kartik Goenka

Question 120

Question

MCQ▾

Which of the following type of class allows only one object of it to be created?

Choices

Choice (4)

a.

Friend Class

b.

Virtual Class

c.

Abstract Class

d.

Singleton Class

Answer

d.

Explanation

  • Singleton pattern is a software design pattern that restricts the instantiation of a class to one object.
  • C ++ Singleton class using inheritance: In this example the base class enforces a singleton pattern.
  • Note that the function calls are static calls to their global names using the scope resolution operator.
  • The functions create () and instance () are defined as static functions in the class definitions.
  • The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects.
Given the Image is Define the Singleton Class in C ++

Developed by: