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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. voidmain ()
  2. {
  3.     printf (“sizeof(void ⚹) =%d”, sizeof (void ⚹) );
  4.     printf (“sizeof(int ⚹) =%d”, sizeof (int ⚹) );
  5.     printf (“sizeof(double ⚹) =%d”, sizeof (double ⚹) );
  6.     printf (“sizeof(structunknown ⚹) =%d”, sizeof (structunknown ⚹) );
  7. }

Explanation

Sizeof (void ⚹) = 2sizeof (int ⚹) = 2sizeof (double ⚹) = 2sizeof (struct unknown ⚹) = 2

  • In the program
Table Shows the Program
printf ( “sizeof (void ⚹) =% d” , sizeof (void ⚹) ) ;
  • The pointer to void type is size of 2
printf ( “sizeof (int ⚹) =% d” , sizeof (int ⚹) ) ;
  • The pointer to integer type is size of 2
printf ( “sizeof (double ⚹) =% d” , sizeof (double ⚹) ) ;
  • The pointer to double type is size of 2
printf ( “sizeof (struct unknown ⚹) =% d” , sizeof (struct unknown ⚹) ) ;
  • The pointer to struct unknown type is size of 2
  • The pointer to any type is of same size.

Question 298

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Differentiate between a for loop and a while loop? What are it uses?

Explanation

Difference between Loop and a While Loop
FOR LoopWHILE Loop
for (initialization; condition; iteration)

{

//body of ‘for’ loop

}

while (condition)

{

Statements; // body of ‘while’ loop

}

For loop runs until the number of predefined iterations are completedWill loop until the condition presented is completed. Condition variables are modified inside the loop
‘For’ loop initialization is never repeated.In while loop if initialization is done during condition checking, then initialization is done each time the loop iterates.

Use of for loop:

  • Used when number of iterations are known beforehand.

Use of while loop:

  • Used when end conditions is known but no idea about the exact number of iterations.

Developed by: