Software Engineer Intern
Interview Questions
Name
Position applied for
Date
Start Time
Environment Cross-platform (Linux, Windows, macOS, and iOS)
Compiler C++ 14/17
1 - Point out as many bugs as possible in the following code.
#include <vector.h>
void main(int argc, char** argv){
int n;
if(argc > 1)
n = argv[0];
int* stuff = new int[n]; ((if n=0))
vector<int> v(100000);
delete [] stuff;
return 0;
2 - What is the output of the following program?
int* foo(){
int k = 3;
k++;
return &k;
void main()
int* p = foo();
printf(“Out = %d, ”, *p);
}
// 4 expected, but gives segmentation fault since ptr is to local variable
3 - What is the output of the following program?
void main(){
static int data[] = {0,1,2,3,4};
int* p[] = {data, data+1, data+2, data+3, data+4};
int** ptr = p;
ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-data, **ptr);
*ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-data, **ptr);
*++ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-data, **ptr);
++* ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-data, **ptr);
// Output? - based on sequence of operators, increment is first, then dereference
// 1 1 1
// 2 2 2
// 3 3 3
// 3 4 4
4 - Can you bypass the password protection without
providing the right password? If yes, how?
#include<stdio.h>
int main(int argc, char* argv[]){
int flag = 0;
char passwd[10];
memset(passwd, 0, sizeof(passwd));
strcpy(passwd, argv[1]);
if(0 == strcmp("rapsodo", passwd))
flag = 1;
if(flag)
printf("\n Pwd matched \n");
else
printf("\n Wrong Pwd \n");
return 0;
// Attack the strcpy by overflowing the stack buffer by providing an input of longer length
// which will overflow the stack and overwrite the value of flag
// input "aaaaaaaaaaa" will crack the password
// Program needs to be compiled with stack protector disabled -fno-stack-protector
5 - Can static variables be declared in a header file in a C program? What happens when such a
header file is included from multiple source files?
6 – What is the difference between an abstract class and interface?
7 – How would you investigate a memory leak in C++?
8 – What are virtual and pure virtual functions?
9 – What is the l-value and r-value reference?
10 – What are the move constructor and assignment, what are their purposes?