Languages-C & C Plus Plus [TCS Placement]: Sample Questions 115 - 116 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 115
Question MCQ▾
Which of the following is not a type of constructor?
Choices
Choice (4) | |
---|---|
a. | Parameterized Constructor |
b. | Default Constructor |
c. | Friend Constructor |
d. | Copy Constructor |
Answer
c.Explanation
- Friend constructor is not a constructor - but friend is used for functions.
- Friend functions are not member functions of a class to which they are a friend.
- Friend functions are declared inside the class using the friend keyword and then they are defined outside the class.
- Friend function can access any member of a class to which it is a friend.
- Friends are functions or whole classes getting access to the private data of a class- breaking encapsulation
- A function cannot make itself a friend of a class without changes to the class.
- A common use of friend functions is to allow the use of << and >> with cout and cin for output and input of user defined types.
Question 116
Describe in Detail Essay▾
Write a loop statement that will show the following output:
1
12
123
1234
12345
EditExplanation
Following program will produce the required output:
#include<stdio.h>
void main()
{
int x,y;
for(x=1;x<=5;x++)
{
for(y=1;y<=x; y++)
printf(“%d”, y);
printf(“”);
}
}