Arista Networks Interview Question for Software Developers
- -1of 1 vote
Answers#include <stdlib.h>
- aristainterview October 19, 2016 in United States
#include <assert.h>
extern int find( int *, int );
int main( int argc, char *argv[] ) {
int o[4][5] = { { 4,6,7,8,9 },
{ 4,5,7,8,9 },
{ 4,5,6,8,9 },
{ 4,5,6,7,9 } };
int e[5][6] = { { 4,6,7,8,9,10 },
{ 4,5,7,8,9,10 },
{ 4,5,6,8,9,10 },
{ 4,5,6,7,9,10 },
{ 4,5,6,7,8,10 } };
int i;
for( i=0; i < 4; i++ )
assert( find( o[ i ], 5 ) == i + 5 );
for( i=0; i < 5; i++ )
assert( find( e[ i ], 6 ) == i + 5 );
printf ("I'm a winner\n");
return 0;
}
#include <stdlib.h>
//
// find( ... )
//
// find takes and array of sorted consecutive positive ints where
// one number is missing and returns the missing number
// find should return 0 on all error conditions
//
// [ 1, 2, 3, 4, 6, 7, 8, 9 ] -> return 5
// [ 11, 12, 13, 15, 16, 17 ] -> return 14
//
/* What's wrong with this program? */
#include <stdio.h>
int
main( int argc, char const * argv ) {
for( int i = 0; i < argc; ++i ) {
printf("%s\n", argv[i] );
}
}
/* Can you tell me what the program will do when I run it like this:
* <prog> 1 2 3 4
*/
/*
Describe what two of these do, and how they're useful for debugging:
perf
oprofile
gprof
strace
gcov
printf
syslog
*/
int main( int argc, char* argv[] ){
char* string1 = "string";
char string2[] = "string";
}
#include <stdio.h>
class C {
public:
void func() {
printf("func called\n");
}
virtual void virtualFunc() {
printf("virtual func called\n");
}
};
int main (int argc, char ** argv) {
C * obj = NULL;
/* What does the following print? */
obj->func();
/* What does the following print? */
obj->virtualFunc();
/* What's the difference? */
}
/* What's polymorphism? */
* What's abstraction? */‘
/* What's a virtual function table? */
/* What's a smart pointer? */
/* What's a copy constructor? */
* Tell me what this expression does: */
/* cout << 3; */
/* What could it do? */
/* Have you ever seen OOP inside a Unix kernel? */
/* What's C++0X? */
/* What is const? */
/* What is name mangling? */
/* What does "extern C" do? */
/* What's std::map? */
write( 1, c, strlen(c) );
/* What does this do? */
printf( "%s", c );
/* What's the difference? */
/* What does malloc do? */
/* What does the '-9' mean in 'kill -9'? */
/* What would kill -11 do? */
/* What's a zombie process? */
/* What does fork return? */
/* What is the return value of main used for? */
* What is select used for? Have you ever heard of epoll? */
struct s {
double f;
int i;
char c[3];
void *p;
int x[0]; }; int main( int argc, char ** argv ) { }
/* How big is a float? */
/* write a program to tell me how big a float is */
/* can you use gdb to show me how big a float is? */
/* How many bytes will structure s take? */
/* Write a quick program to tell me the size of structure s */
/* Does this match what you expected? */
/* What does this do?
#define ABC(x) aaa ## x
ABC(b)
*/
/* How are 1d arrays laid out in C ? */
/* What does the compiler do when you have a statement a[ 5 ] */
/* How do you create dynamically allocated arrays in C and how does the complier generate the memory access for a[ 5 ] */
/* How are 2d arrays laid out in C */
/* How do you create a dynamically allocated 2d array in C such that something like:
int **a = get2dArray( 5, 6)
a[ 2 ][ 3] = 5;
would work properly.*/
/* How would you extend it to create an N dimensional array. Something like:
getNdArray( int n, int * dim)
where n = the number of dimensions, and dim is the actual dimensions.
so you could create a 3d array of size 3,4,5 as
int dim[] = [ 3, 4, 5 ];
int ***a = getNdArray( 3, dim );struct s {
double f;
int i;
char c[3];
void *p;
int x[0];
};
int main( int argc, char ** argv ) {
struct s s1;
printf("%i\n", sizeof(s1.f));
printf("%i\n", sizeof(s1.i));
printf("%i\n", sizeof(s1.c));
printf("%i\n", sizeof(s1.p));
printf("%i\n", sizeof(s1.x));
printf("%i\n", sizeof(s1));
}*/
#include <ctime>
#include <sys/time.h>
#include <iostream>
#include <cstdio>
using namespace std;
/* What do this do? */
int a( unsigned int i ) {
int c = 0;
while( i ) {
if( i & 1 ) { c++; }
i >>= 1;
}
return c;
}
/* What does this one do? */
int b( unsigned int i ) {
static unsigned char n[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
int c = 0;
while( i ) {
c+=n[i&15];
i >>= 4;
}
return c;
}
/* Which one do you think would run faster? */
/* Write a small program that uses the gettimeofday function to
* benchmark these functions.
*
* int gettimeofday(struct timeval *tv, struct timezone *tz);
*
* struct timeval {
* time_t tv_sec; // seconds
* suseconds_t tv_usec; // microseconds
* };
*
* The tz argument can be NULL in this case.
*/
int main( int argc, char **argv ) {
}
#include <ctime>
#include <sys/time.h>
#include <iostream>
#include <cstdio>
using namespace std;
/* What do this do? */
int a( unsigned int i ) {
int c = 0;
while( i ) {
if( i & 1 ) { c++; }
i >>= 1;
}
return c;
}
/* What does this one do? */
int b( unsigned int i ) {
static unsigned char n[] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
int c = 0;
while( i ) {
c+=n[i&15];
i >>= 4;
}
return c;
}
/* Which one do you think would run faster? */
/* Write a small program that uses the gettimeofday function to
* benchmark these functions.
*
* int gettimeofday(struct timeval *tv, struct timezone *tz);
*
* struct timeval {
* time_t tv_sec; // seconds
* suseconds_t tv_usec; // microseconds
* };
*
* The tz argument can be NULL in this case.
*/
int main( int argc, char **argv ) {
struct timeval t1 = {0, 0};
struct timeval t2 = {0, 0};
PROJECT = find
CC = gcc
OBJ = find.o main.o
all: $(PROJECT)
.c.o:
$(CC) -I. -g -c $<
$(PROJECT): $(OBJ)
$(CC) $(OBJ) -o $(PROJECT)
clean:
rm -f find find.o main.o
/*
* describe the code below
*/
struct s {
double f;
int i;
char c[3];
void *p;
int x[0];
};
int main( int argc, char ** argv ) {
struct s new_s;
size_t size = sizeof(new_s.f);
size_t size_i = sizeof(new_s.i);
size_t size_c = sizeof(new_s.c);
size_t size_p = sizeof(new_s.p);
size_t size_x = sizeof(new_s.x);
int size_s = (int) sizeof(new_s);
int total = (int) size + size_i + size_c + size_p + size_x;
printf ("Total: %d", total);
printf ("Struct size: %d", size_s);
return 0;
}
/* How are 1d arrays laid out in C ? */
/* What does the compiler do when you have a statement a[ 5 ] */
/* How do you create dynamically allocated arrays in C and how does the complier generate the memory access for a[ 5 ] */
/* How are 2d arrays laid out in C */
/* How do you create a dynamically allocated 2d array in C such that something like:
int **a = get2dArray( 5, 6)
a[ 2 ][ 3] = 5;
would work properly.*/
/* How would you extend it to create an N dimensional array. Something like:
getNdArray( int n, int * dim)
where n = the number of dimensions, and dim is the actual dimensions.
so you could create a 3d array of size 3,4,5 as
int dim[] = [ 3, 4, 5 ];
int ***a = getNdArray( 3, dim );
*/| Report Duplicate | Flag | PURGE
Arista Networks Software Developer