Search This Blog

C and Data Structures related problems


16 comments:

  1. Why n++ executes faster than n+1?

    ReplyDelete
    Replies
    1. Actually this happens due to instruction involvement in these operation. n++ requires a single instruction whereas n+1 requires more than one instruction to perform this operation.

      Delete
  2. how can we check ,n+1 is taken more tnan one instruction?

    ReplyDelete
  3. n++ requires only inc instruction whereas n+1 first load value in to register then use add instruction to add value 1 in to that register and then finally store in to accumulator. but in n++ a single instruction does all.

    ReplyDelete
  4. There is also other reason to work n++ faster .unary operator execute faster than binary operator.

    ReplyDelete
    Replies
    1. Thanks a lot for clarify this question...

      Delete
  5. What is difference between function overloading and operator overloading?

    ReplyDelete
    Replies
    1. Hello Ritesh, As per my knowledge C does not have any support for function overloading and operator overloading

      Delete
  6. Give a example, In which function returning pointer to structure and where to be use and also what is benefits ?

    ReplyDelete
    Replies
    1. return statement returns only one variable at at time. It is a restriction of returning multiple item through return statement. pointers provide solution for this problem. Placing pointer to different return types, it is possible to return multiple items.
      Struct is group of heterogeneous elements. if we return structure through return statement we can return multiple items as structure member.

      Delete
    2. Bhaiya i understood the theory but can you give a example..

      Delete
    3. typedef struct _record
      {
      int sn;
      char name[20];
      char add[100];
      double age;
      }record;

      record *add_record()
      {
      record *item = (record *)malloc(sizeof(record));
      /*
      * Filling recoed items
      */
      /* ........
      ........


      ........
      */
      return item;
      }

      This one example where function is returning pointer to structure

      Delete
  7. Explain with example inline function and where to be use and what is advantage ?

    ReplyDelete
    Replies
    1. Inline function is used to reduce the overhead of call and return sequence of a function. using inline keyword we make a function inline.
      Ex-
      inline int add(int a, int b)
      {
      return (a+b);
      }
      if we call add() function from any part of our code the caller function is replaced bu its function body.
      You can use inline for optimization of your code. When some function requires frequent call you can use inline.

      Delete
  8. How to find pivot in quick sort ?

    ReplyDelete