Cisco Systems Interview Question






Comment hidden because of low score. Click to expand.
0
of 0 vote

int * arr = (int * ) malloc(sizeof(int)*nrows*ncols);

- Anonymous November 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int **dd;
int i;
int row,col;

scanf("%d",&row);
scanf("%d",&col);

dd = malloc(sizeof(int*) * row);

for(i=0;i<row;i++)
dd[i] = malloc(sizeof(int)*col);

- matrix November 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Got the code from some forum.

int main()
{
  int i; /* general purpose variable used for loop index */
  int j; /* general purpose variable used for loop index */


  int **a;     /* this is the array name */
  int size_x; /* this variable will be used for the first  dimension */
  int size_y; /* this variable will be used for the second dimension */


  /* suppose we want an array of int: a[5][3] */
  size_x = 5;
  size_y = 3;

  /*  allocate storage for an array of pointers */

  a = malloc(size_x * sizeof(int *));

  /* for each pointer, allocate storage for an array of ints */
  for (i = 0; i < size_x; i++) {

    a[i] = malloc(size_y * sizeof(int));
  }

  /* just for kicks, show the addresses (note: not all sequential) */
  /* assign an arbitrary value to each element        */

  for (i = 0; i < size_x; i++) {
    for (j = 0; j < size_y; j++) {
      printf("&a[%d][%d] = %p\n", i, j, &a[i][j]); /* show the addresses */

      a[i][j] = i * size_y + j; /* just some unique number for each element */
    }
    printf ("\n");
  }

  /* now show the contents that were assigned */

  for (i = 0; i < size_x; i++) {
    for (j = 0; j < size_y; j++) {
      printf("a[%d][%d] = %2d\n", i, j, a[i][j]);

    }
    printf ("\n");
  }

  /* now for each pointer, free its array of ints */
  for (i = 0; i < size_y; i++) {

    free(a[i]);
  }
  /* now free the array of pointers */
  free(a);

  return 0;
}

- Vaishnavi November 24, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int (*a)[columns] = malloc(sizeof(a) * rows);

- RajiniHassan January 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int **a;
get row1 and col1
// allocate required space for given dimension
space1 = (int*) malloc(sizeof(int)*row1*col1);

// allocate row pointers
a = (int**) malloc(sizeof(int*)* row1);

// break regions and assign the row pointers
for(i=0; i<row1; i++)
a[i] = space1 +(i*col1);

//Advantage reduced number of mallocs

- chidanand February 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

template<class T>
bool make2DArray(T**& x, int rows, int cols) {
  try{
  x = new T*[rows]; // S* x = new S[rows], with S = T*;
  for (int i=0; i<rows; i++)
    x[i] = new T[cols];
  return true;}
  catch (xallox) {return false;}
}

bool delete2DArray(T**& x, int rows) {
  for (int i=0; i<rows; i++)
    delete [] x[i];
  delete [] x; // confirm this
  x = 0; // x is just the null pointer
}

- Anonymous May 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int row, col;
	int **ARR;
	row = 3;
	col = 4;

	ARR = (int **)malloc(row * sizeof(int*));
	for(int i = 0; i<row; i++)
	{
		ARR[i] = (int*)malloc(col * sizeof(int));
	}

- SSS October 27, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

correct............

- hunter July 17, 2013 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More