Interview Questions and Notes

Coding, Programming, Software interview questions, examples and references


Last Updated: February 04, 2020 by Pepe Sandoval



Want to show support?

If you find the information in this page useful and want to show your support, you can make a donation

Use PayPal

This will help me to create more stuff and fix the existent content... or probably your money will be used to buy beer


Index

General Computers Architecture and Digital Hardware Questions

Programming

Linux & Operating Systems Questions

Embedded Systems & RTOS Questions

Validation, Verification, Testing...

Other Questions

External references to practice coding

Codility
Hacker Rank

General Computers Architecture and Digital Hardware Questions

  1. Do you know the Harvard and Von Neumann architectures? What is its main difference?
  1. Do you know about the RISC and CISC instruction set architectures (ISA)? What are some of their (main) characteristics?
  1. Do you know about the memory hierarchy? Why do we need it? Why not just use fast memory (cache)?
  1. What are the most common stages of execution of an instruction in a simple RISC architecture?
  1. In processors context What's Pipeline? And why do we use it? Why not implement as a unicycle?
  1. What is cache coherence
  1. Can you draw a CPU architecture diagram or its main blocks?
  1. In computer architecture what defines whether a system is a 32-bits or 64-bits system?
    • a) Register Size
    • b) Memory data buses
    • c) Memory address buses

Programing

C General Programing Questions

  1. Which of the following is NOT a reserved word in C?
    • a) sizeof
    • b) try
    • c) signed
    • d) register
  1. According with the following code, which is the output after its execution?
     #define EOF_INT_SHIFT 4
     printf("%x\r\n", 1<<EOF_INT_SHIFT + 0x02);
    • a) 12
    • b) 34
    • c) 40
    • d) 18
  1. According with the following code, which is the output after its execution?

    #include <stdio.h>
    #define EOF_INT 0x0020
    
    int main(int argc, char *argv[]) {
       unsigned char int_status = 0x001F;
       unsigned char int_event = 0;
    
       if(int_status & EOF_INT != 0)
         int_event |= EOF_INT;
       else
         int_event &= ~EOF_INT;
    
       printf("%d\n", int_event);
    }
    
    • a) 32
    • b) 20
    • c) 0
  1. The result of the following operation: !(0 || !1 && 0 || 3 && 1) is?
    • a) true
    • b) false
    • c) Invalid operation
    • d) Compiler error
  1. What would be the result of compiling black.c and blue.c files separately and then calling the linker to combine them in a single program
    linker problem
    • a) Compilation error
    • d) Link error
    • c) The program may be created (depends on linker)
  1. According with the following code, which is the output after its execution?

    #include <stdio.h>
    #define MULTIPLY(x,y) (x*y)
    
    int main(int argc, char *argv[]) {
       int a = 2;
       int b = 4;
       int c = 5;
       printf("%d\n", MULTIPLY(a+b, c++));
    }
    
    • a) 26
    • b) 36
    • c) 23
    • d) 22
  1. According with the following code, which is the output after its execution?

    #include <stdio.h>
    #define DEBUG 0
    
    int main(int argc, char *argv[]) {
    #ifdef DEBUG
       float x = 3/2;
       printf("%f\n",x);
    #else
       printf("DEBUG OFF\n");
    #endif
    }
    
    • a) 1.5000
    • b) DEBUG OFF
    • c) 1.000
    • d) Invalid code
  1. If you keep incrementing a variable, will this variable become negative at some point?
    • a) true
    • b) false
    • c) Depends on _________
  1. According with the following code, which is the output after its execution?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
       unsigned x[10] = {0,0,0,0,0,0,0,0,0,0};
       unsigned * px = x;
       printf("%d, %d\n",sizeof(x), sizeof(px));
    }
    
    • a) Depends on _________
    • b) 40, 4
    • c) 10, 4
    • d) 10, 10
    • e) 40, 40
    • f) 4, 4
    • g) Compilation error
  1. How many times does the following loop run? for(x=0; x=3; x++)
    • a) Three times
    • b) Four Times
    • c) Never
    • d) Forever
  1. Which is the output after running the following code?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int x;
      while(x < 100) {
        printf("%d, ",x);
        x++;
      }
    }
    
    • a) 0, 1, 2, 3, ... 99,
    • b) 0, 1, 2, 3, ... 100,
    • c) Undefined
  1. According with the following code, which is the output after its execution? Semicolon at line 5 is not a typing error, it is part of the C code.

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int i = 0, x = 0;
      for(i=0; i<10; i++);
      {
        x++;
      }
      printf("%d\n", x);
    }
    
    • a) 0
    • b) 1
    • c) 10
    • d) Compilation Error
  1. Which is the output after running the following code?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int i = 0;
      while(i++<10);
      printf("%d\n", i);
    }
    
    • a) 9
    • b) 10
    • c) 11
    • d) Compilation Error
  1. Which is the output after running the following code?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int i = 0;
      int x = 0;
      for(i=0; i<10; i++){
        if((i>2) && (i<5))
          continue;
        if(i==8)
          break;
        x++;
      }
      printf("%d, %d\n",x,i);
    }
    
    • a) 10, 10
    • b) 10, 8
    • c) 8, 8
    • d) 6, 8
  1. What does the following code mean: for(;;);
    • a) Invalid Code
    • b) Infinite loop
    • c) Ignored by the compiler
    • c) Compiler error
  1. According with the following code?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int x = 1;
      int* p = &x;
      *p = 2;
      *p++ = 10;
    
      printf("%d\n",x);
    }
    
    1. 15-1. What is the value of x printed?
      • a) 2
      • b) 3
      • c) 10
      • d) 11
    2. 15-2. Does the pointer p points to a variable defined in main?
      • b) Yes, points to the variable x
      • b) No
  1. What is a macro in C? Can you provide an example?
  1. How would you define a type using typedef? What's the difference between defining a type using typedef and with a macro, using #define?
  1. Which is the output after executing the following code?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int a = 0;
      int b = 1;
      int c = 2;
      c = (a > b) ? a : b++;
      printf("%d %d %d\n", a, b, c);
    }
    
    • a) 0 2 1
    • b) 2 0 2
    • c) 0 2 2
    • d) Invalid code
  1. Assuming a compiler that supports C99 and according with the following code, which is the output after its execution?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      // Struct Definition
      struct node {
                      int a;
                      int b;
                      int c;
                  };
    
      // Structs declarations
      struct node s = { 5, 13, 6 };
      struct node z = { b:14, c:2, a:7 };
    
      // Pointers
      struct node *pt = &s;
      struct node *ptz = &z;
    
      printf("pt=%d ptz=%d\n" , * (int*)pt , * (int*)ptz );
    }
    
    • a) pt=13 ptz=14
    • b) pt=5 ptz=7
    • c) pt=5 ptz=14
    • d) Invalid Code
    • e) Compilation Error
  1. What is the difference, related to memory, between a local variable, global variable and a variable allocated with malloc (dynamic)?
  1. Which operator is used to access a member of a structure referenced by a pointer?
    • a) *
    • b) ->
    • c) >>
    • d) &
  1. Assuming a 32-bit system where int variables are 4-bytes long and not specificing any pragmas, which is the output after the execution of the following code?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
        typedef struct _SMX_ {
          int x;
          char a;
          int y;
          char b;
          int z;
          char c;
        } SMX, * P_SMX;
    
        typedef struct _BAS_ {
          int x;
          int y;
          int z;
          char a;
          char b;
          char c;
        } BAS, * P_BAS;
    
        printf("%d %d\n", sizeof (SMX), sizeof (BAS));
    }
    
    • a) 15 15
    • b) 6 6
    • c) 24 16 . Due to not specifying it declaration order will cause more memory to be used.
    • d) 16 16
    • e) Compile error, becasue the way sizeof is used on custom types
  1. Which character is used to terminate the strings in C?
    • a) .
    • b) \x
    • c) \END
    • d) \0
  1. Which is the output after executing the following code?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int arr[] = {8, 7, 6, 5, 4, 3, 2};
      printf("%d\n" , *(arr+2)+1 );
    }
    
    • a) 7
    • b) 8
    • c) 6
    • d) 5
  1. According with the following code, which is the output after its execution?

    #include <stdio.h>
    
    void f1(int *, int);
    void f2(int *, int);
    void(*p[2]) (int*, int);
    
    int main(int argc, char *argv[]) {
        int a = 3;
        int b = 5;
        p[0] = f1;
        p[1] = f2;
    
        p[0](&a , b);
        printf(" %d %d " , a ,b);
    
        p[1](&b , a);
        printf(" %d %d " , a ,b);
    }
    
    void f1(int* p , int q){
      int tmp;
      tmp = *p;
      *p = q;
      q = tmp;
    }
    
    void f2(int* p , int q){
      int tmp;
      tmp = *p;
      *p = q;
      q = tmp;
    }
    
    • a) 5 3 5 3
    • b) 3 5 3 5
    • c) 5 5 5 5
    • d) 3 3 3 3
  1. Which is the output of the following program?

    #include <stdio.h>
    
    int counter (int i) {
        static int count = 0;
        count = count + i;
        return (count);
    }
    
    int main(int argc, char *argv[]) {
        int i , j;
        for (i = 0; i <= 5; i++)
        j = counter(i);
        printf("%d\n", j);
    }
    
    • a) 10
    • b) 15
    • c) 5
    • d) 4
  1. What's the return value of the following function calling it with v = 13?

    #include <stdio.h>
    
    int fn(int v) {
      if (v == 1 || v == 0) return 1;
      if (v%2 == 0) return fn(v/2) + 2;
      else return fn(v-1) + 3;
    }
    
    • a) 13
    • b) 10
    • c) 16
    • d) Invalid Code
    • e) Runtime error
  1. Assuming a 32-bit architecture which of the following data structures uses less memory?
    • a) struct mystruct { int i; float f; int b; };
    • b) union myunion { unsigned int ui; float f; char c[4]; };
    • c) char array[10];
  1. Which code represents a call to a function which is located at the address 0 of the system memory?
    • a) (*(void(*)(0)))();
    • b) (*(void(*)()0))();
    • c) (*(void(*)())0)();
  1. According with the following code, which is the output after its execution?

    #include <stdio.h>
    
    int main(int argc, char *argv[]) {
      int x[] = {3, 5, 2, 4};
      int y = 0;
      int i = 1;
    
      y = i + x[i++];
      x[i] = y + i++;
    
      printf("%d ",y);
      for(i=0; i<4; i++) { printf("%d ",x[i]); }
    }
    
    • a) Undefined
    • b) 7 3 5 9 4
    • c) 6 3 5 8 4
    • d) 7 3 5 2 9
  1. What does the following declaration mean in C? int func();
    • a) func is a function with any number and type of arguments.
    • b) func is a function with no arguments.
    • c) func would receive a single int argument as default.
    • d) Invalid function declaration
  1. What does the volatile modifer means?
  1. What is the build process of a C program?

C Coding Problems

  1. Write a function in C that calculates the factorial of a given number. Function takes as input an integer and returns the factorial of that number

  1. Write a function in C that calculates the Fibonacci series ([0, 1, 1, 2, 3, 5, 8, 13, 21]). Function takes as input an integer representing the position of the Fibonacci series and returns the corresponding value of Fibonacci Serie for that posistion

  1. Write a function in C that performs bubble sort search in an array. Function takes as input the array and size and sorts it

  1. Write a function in C that inverts the values of an array. Function takes as input an array and modifies it accordingly

  1. Write a function in C that counts the number of bits set to 1 in a variable. Function takes as input the variable and returns a number representing the number of bits set

  1. Write a function to invert the order of the bits in a variable. Function must receive a pointer to the variable and the change must occur in the space of memory pointed by that argument.

    Invert bits

  1. Using C syntax declare a function that returns the sum of two integers, then declare a function pointer that points to that function and call the function using the pointer to the function. Can we call the function using the following syntax (*pFunc)(1, 2); ?

  2. Write a function that detects endianness. For example it returns 1 if running on a Little-Endian architecture and 0 when running on a Big-Endian one.

  1. Write a function to convert a 32-bit int variable from Little-Endian to Big-Endian. Function must receive a pointer to the int that we would like to change and the change must occur in the space of memory pointed by that argument.
    Hint: little endian -> least significant first ; big-endian -> most significant first

    Endianness

  1. Write a function to add matrixes. Function receives as paramaters pointers to the matrixes, the number of rows and colums and should work for any matrix size. The function must return a pointer to the beginning of the resulting matrix. Global variables for any of the matrixes can be used

  1. Write a function to multiply matrixes. Function receives as paramaters pointers to the matrixes, the number of rows and colums of each matrix and should check if multiplication is possible. The function must return a pointer to the beginning of the resulting matrix. Global variables for any of the matrixes can be used

  2. Implement an interface for a Stack (LIFO) data structure in C, it must consist of at least 2 functions to push and pop data from the Stack

  1. Implement an interface for a Queue (FIFO) data structure in C, it must consist of at least 2 functions to add and get data from the Queue

  1. Implement an interface for a Linked List data structure in C, it must consist of at least 2 functions: 1) append which adds elements at the end of the list, 2) get which removes an element from certain index data from the Linked List and returns the value stored in that index


General Object Oriented Programming (OOP) Questions

  1. What is a class? an object? What are its two main components?
  1. What are the main characteristics of OOP (Object Oriented Programming)?

C++ General Programming Questions

  1. What is the auto reserved word in used for in C++?
  1. In the context of C++ what's a reference? What's the difference between a reference and a pointer
  1. In the context of C++ what are templates? What are they used for?

  1. In the context of C++ what is Operator Overloading? what is it used for?
  1. In the context of C++ what's a virtual function and a pure virtual? What are they used for?


C++ Coding

  1. Write a functions that swaps two values? Function must use C++ references.

  2. Define the following class hierachy in C++:

    • create a class Person which has the attributes name (string) and age (unsigned int), it's constructor must receive these as parametert to init attributes. This class has a method called print that prints name and age of the person
    • create a class Student that inherits from Person to include an attribute school (string), it's constructor inits this attribute and calls base class to init the other attributes. Student class overwrites the base class print method to now print name, age and school of the student
    • Overload operator ++ in the class Person to increment the age atrribute when called. E.g. the code Person p1("Jose", "27"); ++p1; should run and make age attribute of p1 equals to 28
    • Create a std::shared_ptr; of type Person that points to a newly created instance of Student (use the operator new to create this instance) and call the function print using this pointer


Python General Programming Questions

  1. In Python what is the difference between lists, tuples and sets?

  2. Python is a compiled or interpreted language and what this means?

  3. What is a decorator in Python?

  4. What is an anonymous function in Python and how it works?


Python Coding

  1. Write a program in Python that when executed will prompt the user for text input and reply with the correct response as provided in the following table. The program should continue to prompt for input and reply with the appropriate response until an input value is provided that is not valid, i.e. not in the table. Please make all input case insensitive.
input output
Red Green
Green Black
Black Blue
Blue Yellow
Yellow Red
White Black
Purple Green
  1. Write a function in Python that receives as a parameter a string and returns the first character that is repeated in that string, returns None if no character is repeated
  1. Write a function in Python that receives an integer and returns in a list all the divisors of that number
  1. Write a function in Python that receives a list of integers and returns a list of the same size where each element is created by the multiplication of all the other elements of the list received as parameter except for the one in the index you are trying to calculate. So for example given the list [1, 2, 3, 4] it returns [24, 12, 8, 6] because for index 0: it multiples 2x3x4=24 avoiding the value 1, for index 1: 1x3x4=12 avoiding the value 2 and so on...
  1. Write a function in Python that receives a list of integers (positive and negative) and returns the sum of all the two digit numbers in that list so for example given the list [1, 1000, 80, -91] it returns -11 because it's the sum of 80 and -91 (-91+80=-11)
  1. Consider the format HH:MM:SS to define a certain point in time of the day for example 16:11:16 to describe 4:11pm with 16 seconds. A point in time, like this one, is considered "interesting" if it needs 2 or less different digits to represent it so the previous example would be considered "interesting" because it only needs the digits 1 and 6.

    Considering this definition of "interesting", write a function in Python that receives a start (S) and end (T) points in time in the format HH:MM:SS and returns the number of points considered "interesting" between this time interval including both limits (S and T), under the assumption T will always be a later time than (S). So for example given S="22:22:21" and T="22:22:23" as inputs to your function it should return 3 because 22:22:21, 22:22:22 and 22:22:23 are all considered "interesting"

  1. Binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has a binary representation 1001 and contains a binary gap of length 2, numbers 32(100000) and 15 (1111) have no binary gaps, while 545(1000100001) and 529(1000010001) contains two binary gaps: one of length 4 and one of length 3 each

    Considering this definition of "binary gap", write a function that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.

  1. A right rotation of an array shifts each element of the array 1 unit to the right and the last element of the array is moved to the first place. For example [3, 8, 9, 7, 6] right rotated 3 times is -> [9, 7, 6, 3, 8]. A left rotation of an array shifts each element of the array 1 unit to the left and the first element of the array is moved to the last place For example [1, 2, 3, 4, 5] left rotated 4 times is -> [5, 1, 2, 3, 4].

    Considering this, write two functions that, given an array A consisting of N integers and an integer K, returns the array A rotated K times, one function must return the array rotated to the right and the other the array rotated to the left

  1. Write a function in Python, that given two strings as inputs returns whether one is an anagram of the other, for example it returns True for the inputs night and thing

Linux & Operating Systems Questions

  1. What is the kernel of an OS?
  1. What's the difference between user mode and kernel mode?
  1. What do applications running in user mode use to request a service from the OS
  1. What is a Linux Distribution? What differentiate Linux distributions?
  1. What do you need to compile the Linux kernel?
  1. What is the difference between a Thread and a Process?


Embedded Systems & RTOS Questions

  1. What is a Timer?
  1. What is an Interrupt?
  1. How does an ADC work in general?

  2. What is the difference between ROM and Flash memory?

  1. What is the difference between a HW breakpoint and a SW breakpoint?
  1. What is a Race Condition?

Validation, Verificaion, Testing

  1. What is the difference between Validation and Verification?
  1. What is a Test Case and an Use Case?
  1. What is a Test Plan?
  1. What is a Bug?
  1. From the testing perspective what is done when a Bug is found? What is the Bug life cycle from a testing perspective?
  1. What is the difference between 'White Box' and 'Black Box' Testing?

Other Questions

  1. Explain what is make and a Makefile?

  2. What is the difference between a Shared and a Static Library?

  3. In a software context what is the main difference between a Framework and a Library?

Want to show support?

If you find the information in this page useful and want to show your support, you can make a donation

Use PayPal

This will help me to create more stuff and fix the existent content... or probably your money will be used to buy beer