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

C & C Plus Plus

Describe in Detail


How would you use qsort () function to sort an array of structures?


  • qsort () is an standard C library function, for sorting an array.
  • It uses two argument one of which contains logic to decide order in sorted output.
  • This provides flexibility so qsort () to use many types and can be used to obtain any desired order.
  • The compare function takes two pointers as arguments and defines the order.
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedefstructemp_list
  4. {
  5.     intid;
  6.     charname[10];
  7. }
  8. EMP;
  9. intsorting_mech( constvoid ⚹ele1 , constvoid ⚹ele2)
  10. {
  11.     inta,b;
  12.     a =⚹((int ⚹)ele1);
  13.     b =⚹((int ⚹)ele2);
  14.     if( a >b)
  15.     {
  16.         return1;
  17.     }
  18.     if(a <b )
  19.     {
  20.         return -1;
  21.     }
  22.     return0;
  23. }
  24. qsort(&emp_list_array, &sorting_mech);

The function sorting_mech will be called by the qsort to sort order employees whenever there is need.

Question 327

C & C Plus Plus

Write in Short

Short Answer▾

What do the ‘c’ and ‘v’ in argc and argv stand for?


Understanding of Argc and Argv
  • Here, “c” stands for counter and “v” stands for vector (basically an array) .
  • The argc and argv are used when inputs are taken through the command line or terminal itself.
  • Argc is integer variable denoting the number of arguments, argv is the array of the strings signifying the various arguments strings.

Developed by: