Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 36 - 38 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 36

C & C Plus Plus
Edit

Write in Short

What are the conditions that have to be met for a condition to be an invariant of the class?

Explanation

• The condition should hold at the end of every constructor.
• The condition should hold at the end of every mutator (non-const) operation.

Question 37

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Which bit wise operator is suitable for checking whether a particular bit is on or off?

Explanation

• Operator is suitable for checking weather particular bit is on or off.
• For example,
• Suppose in byte has value 10101101.
• We check whether bit number 3 is ON (1) or OFF (0) .
• For checking bit number 3, the second operand for AND operation is binary 00001000, which is equal to 8 in decimal.

• Since the resulting value is 8, that is value of the second operand the bit was ON
• If the answer was 0, the bit number 3 in the resulting bit pattern would have evaluated 0 and complete bit pattern have 00000000.

Question 38

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Find the output for the following C program

1. main ()
2. {
3.     char ⚹p1 =“Name” ;
4.     char ⚹p2;
5.     p2 =(char ⚹) malloc(20);
6.     while ( ⚹p2 ++ =⚹ p1 ++ );
7.     printf ( “%s”, p2);
8. }

Explanation

• In the program
 char ⚹ p1 = “Name” ; define the character pointer p1 = “Name” char ⚹ p2; define the character pointer p2 p2 = (char ⚹) malloc (20) ; using the malloc () functionvoid ⚹ malloc (size_t size) allocates the requested memory and returns a pointer to it. while (⚹ p2 ++ =⚹ p1 ++) ; apply the while condition printf ( “% s” , p2) ; printf prints the pointer p2 valuepointer p2 has no string so it is empty string

Developed by: