0% found this document useful (0 votes)
34 views

Software Engineer Intern Interview Questions

The document contains interview questions for a software engineer intern position. The questions cover topics like C++, pointers, static variables, abstract classes, interfaces, virtual functions, references, and move semantics.

Uploaded by

sagar.sureka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Software Engineer Intern Interview Questions

The document contains interview questions for a software engineer intern position. The questions cover topics like C++, pointers, static variables, abstract classes, interfaces, virtual functions, references, and move semantics.

Uploaded by

sagar.sureka
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

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?

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy