Languages-C & C Plus Plus [TCS Placement]: Sample Questions 56 - 58 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 56

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Write a simple code fragment that checks if a number is positive or negative?

Explanation

Program is as below:

  1. #include<stdio.h>
  2. voidmain()
  3. {
  4.     intnum;
  5.     printf(“Enteranumber”);
  6.     scanf(“%d”, &num);
  7.     if(num>=0)
  8.     printf(“%disapositivenumber”, num);
  9.     else
  10.     printf(“%disanegativenumber”, num);
  11. }

Output:

Case: 1

Enter a number

-25

-25 is a negative number

Case: 2

Enter a number

63

63 is a positive number

Question 57

C & C Plus Plus

Question

MCQ▾

Destructor has the same name as the constructor and it is preceded by ________

Choices

Choice (4)

a.

?

b.

~

c.

$

d.

!

Answer

b.

Explanation

  • ~ (tield) sign is used to declare destructor.
  • Destructor destroys the memory allocated by constructor.
  • Destructor cannot be inherited.
  • Destructor is called when an object is destroyed.
  • The destructor must have the same name as the class; precede by a tilde (~) .
  • The destructor cannot take arguments and has no return type.
Given the Image is Define the Destructor in C ++

Question 58

C & C Plus Plus
Edit

Statement

True-False▾

Not all reserved words are written in lowercase.

Answer

FALSE

Explanation

  • FALSE.
  • All reserved words must be written in lowercase; otherwise the C compiler would interpret this as unidentified and invalid.
Given the Image Defining the Reserved Words Are in Lowercase

Developed by: