Qualcomm System Architect | Embedded Systems Mock Interview | Prepalced

Поделиться
HTML-код
  • Опубликовано: 29 авг 2024

Комментарии • 24

  • @EricBrown-ks7sd
    @EricBrown-ks7sd 2 года назад +9

    I believe the answer to Q1 is incorrect. The interviewer and interviewee both state that the code will run into a segmentation fault when trying to evaluate ptr->a.
    Because the if statement is an AND and the first expression is evaluated to false, the second (ptr->a) would not be evaluated, and thus not throw an segmentation fault. The output of the run would be the print("reached outside if
    ") and it will return 0.

    • @preplaced
      @preplaced  2 года назад +4

      Eric, you are absolutely correct about the case of AND expression. Actually, there are 2 cases being described in the question:
      Case 1: Where the question is // if(ptr->a)
      In this case, the answer will be segmentation fault
      Case 2: Where the question is // if(ptr && ptr->) ------- Discussed at time 3:57
      In this case, ptr->a wouldn't be evaluated as the condition fails at ptr itself and there will be no segmentation fault.
      The confusion is probably because the image of the question stays the same throughout the discussion of Q1.

  • @amu874
    @amu874 2 года назад +3

    Perspicacious mock interview. Very useful 🔝🔝

  • @z.s.1350
    @z.s.1350 2 года назад +2

    though generally the bad quality of sound and unsynchronised screen( especially Q3), it is insightful and helpful, thanks.

  • @diyakameria5758
    @diyakameria5758 2 года назад +2

    This is really useful

  • @prachigupta1713
    @prachigupta1713 2 года назад +1

    Really insightful mock test!

  • @somashekarswamymm7903
    @somashekarswamymm7903 Год назад

    Good way of given a feedback

  • @JoshGuilfoyle
    @JoshGuilfoyle 11 месяцев назад

    This video tells us exactly why we need to stop using C. It's scary to imagine all the security flaws the interviewee has been writing before and after this interview :)

  • @nikhilwardrobe
    @nikhilwardrobe Год назад

    Is this guy a fresher or an experienced candidate?

  • @ritiksharma1229
    @ritiksharma1229 Год назад

    it was good but he said to clear the basics, so i am sure the interviewee had studies from books you tube and had same understanding as me, but how can he improve, if he revise from same sources he will again get confused so what are these sources from where he can get his basics right

  • @satvikkhare1844
    @satvikkhare1844 2 года назад +2

    The candidate needs preparation. He is often confused. I guess he won't be able to make it if he gives the interview immediately after this.
    The questions are very good. It is like a masterclass in pointers.

  • @behnamheydarshahi6535
    @behnamheydarshahi6535 2 года назад

    Could you please comment the code of question 4 (changing pointer value through a function cell) before and after correction?

    • @preplaced
      @preplaced  2 года назад +1

      Behnam Heydarshahi, below are the code snippets as requested by you:
      //---Before Correction:---//
      void fun(int *p)
      {
      int q = 10;
      p = &q;
      }
      int main()
      {
      int r = 20;
      int *p = &r;
      fun(p);
      printf("%d", *p);
      return 0;
      }
      //---After Correction:---//
      void fun(int **pptr)
      {
      static int q = 10;
      *pptr = &q;
      }
      int main()
      {
      int r = 20;
      int *p = &r;
      fun(&p);
      printf("%d", *p);
      return 0;
      }

    • @AnjaliVerma-bg9oy
      @AnjaliVerma-bg9oy 2 года назад

      @@preplaced printf("%d",*p); // output will address of r.
      Right?

  • @rishabhsheth6087
    @rishabhsheth6087 Год назад +1

    Q4)
    I think it's illegal to access memory pointed by p once function fun() is called. We could get segmentation fault or garbage. Because:
    i.e. ideally once the function is done, the variable goes out of scope. However here somehow memory is still there and not changed by some other function/program so we get the correct answer.
    Let me know if my understanding is not correct. Please refer following:
    #include
    #include
    void fun(int **p){
    int q=10;
    printf("q=%p, p=%p
    ", &q, *p);
    *p = &q;
    printf("q=%p, p=%p
    ", &q, *p);
    }
    int main(){
    int r = 20;
    int *p = &r;
    printf("&r=%p, p=%p
    ", &r, p);
    fun(&p);
    printf("*p = %d
    ",*p);
    *p = 50;
    printf("Value &p=%p *p=%d r=%d
    ", p, *p, r);
    return 0;
    }
    I got the following output:
    &r=0x7fffd5428e5c, p=0x7fffd5428e5c
    q=0x7fffd5428e34, p=0x7fffd5428e5c
    q=0x7fffd5428e34, p=0x7fffd5428e34
    *p = 10
    Value &p=0x7fffd5428e34 *p=50 r=20

  • @vikaskumarthakur9581
    @vikaskumarthakur9581 2 года назад

    These all are C programming snippets?so if we want to build our career in embedded then we should know about C programming , isn't it,i have done my btech in ece and having good knowledge of core subjects like digital electronics and analog electronics,edc 🤔?

  • @bharathbhatt4123
    @bharathbhatt4123 2 года назад

    I'm I the only one or for problem 5 "10" is the output. I tried executing the code too, it gives 10. Can someone explain?

    • @preplaced
      @preplaced  2 года назад

      // Explanation: Inside fun(), q is a copy of the pointer p.
      // So if we change q to point something else then p remains uneffected.
      // If we want to change a local pointer of one function inside another function,
      // then we must pass pointer to the pointer. By passing the pointer to the pointer,
      // we can change pointer to point to something else. See the following program as an example.
      void fun(int **pptr)
      {
      static int q = 10;
      *pptr = &q;
      }
      int main()
      {
      int r = 20;
      int *p = &r;
      fun(&p);
      printf("%d", *p);
      return 0;
      }
      // In the above example, the function fun() expects a double pointer (pointer to a pointer to an integer).
      // fun() modifies the value at address pptr. The value at address pptr is pointer p as we pass adderess of p to fun().
      // In fun(), value at pptr is changed to address of q. Therefore, pointer p of main() is changed to point to a new variable q.

    • @adityagupta9719
      @adityagupta9719 2 года назад

      @@preplaced so i guess 10 is the correct

    • @adityagupta9719
      @adityagupta9719 2 года назад

      @@preplaced can someone explain what happens in Q4 if we write *p in parameter instead of **p

    • @preplaced
      @preplaced  2 года назад

      @@adityagupta9719 , Yes, the output will be 10 when we use the double pointer. And 20 when double pointer is not used.

    • @preplaced
      @preplaced  2 года назад

      @@adityagupta9719 The explanation is as mentioned above in the previous comment. When you use *p instead of **p, it just passes the value and not the address to the pointer. Hence, the output will be 20 in that case.