Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 319 - 321 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 319

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is a template?

Explanation

  • Template is foundation of generic programming, which involves writing code in independent of any particular type.
  • Provides blueprint for creating a generic class or a function.
  • Library containers like iterators and algorithms are examples of generic programming developed using templates.
  • For example a vector containing different kinds can be declared as vector < int > or < string > .

Two types of template:

Function Templates

  • Write a generic function that used for different data types.
  • Class Template
  • Function template, class templates are useful when a class defines are independent of data type.
Two Types of Template

Question 320

C & C Plus Plus
Edit

Write in Short

Short Answer▾

Which bit wise operator is suitable for turning off a particular bit in a number?

Explanation

  • The bitwise AND operator.

Function syntax:

BitAND (number1, number2)

  • Number1 is defined as 32-bit signed integer and number2 is also defined as 32-bit signed integer.
  • Bit functions operate on 32-bit signed integers, in the range -2147483648 - 2147483647.

Question 321

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. #include<stdio.h>
  2. main ()
  3. {
  4.     intx, y =2, z, a;
  5.     if (x =y%2) z =2;
  6.     a =2;
  7.     printf ( “%d %d” z, x);
  8. }

Explanation

  • In the program
Table Shows the Program
int x, y = 2, z, a;Declare and define the integer variables x, z, a and y = 2
if (x = y % 2) z = 2;
  • The value of y % 2 (remainder) is 0.
  • This is assigned to x.
  • The condition reduces to if (x) or in other words if (0) and z goes in initialized.
printf ( “% d % d” z, x) ;Printf prints the garbage value of z and x as 0
  • Thumb rule: check all control paths to write bug free code.

Developed by: