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

C & C Plus Plus

Describe in Detail

  1. main ()
  2. {
  3.     chars[ ] =“man
  4.     inti;
  5.     for (i =0; s[ i ]; i ++ )
  6.     printf ( “%c%c%c%c” s[ i ], ⚹(s +i), ⚹(i +s), i[s]);
  7. }


  • In a program
Table Shows the Program
char s [] = “man”Character array
int i;Index number
for (i = 0; s [i] ; i ++)Apply for loop for change the array value
  • Here s [i] , ⚹ (s + i) , ⚹ (i + s) , i [s] are all different ways of expressing the same idea.
  • Generally array name is the base address, so here s is the base address.
  • i is the index number from the base address.
  • So, indirectly ⚹ is same as s [i] .
  • i [s] may be different, but in the case of c it is same as s [i] .
  • So, the first time going to loop print the mmmm.
  • Second time going to loop print the aaaa.
  • And third times going to loop print the nnnn.

Question 158

C & C Plus Plus

Write in Short

Short Answer▾

Out of fgets () and gets () which function is safe to use and why?


  • The fgets () function is safer to use.
  • Checks the bounds- the size of the buffer and prevents overflow on the stack.
  • The gets () function does not check the bounds.
  • The gets () function is insecure and lead to errors and security vulnerabilities.

Developed by: