Cisco Systems Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

AFAIK , when any number is compared to 0 , it will be OR'd with 0xfffffff , .. so 1 and 0 in first case which is 1 it will skip .. but in 2 | 0 , it will check 0th bit and first bit as well. hence there is one more instruction check in this case... plz correct me if i m wrng

- gopi.komanduri July 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The answer doesn't seem right. If OR operation is to be performed on two registers(holding 1 and 0xFFFFFFFF), the comparison of all bit will be performed as a result of one assembly command. I do not think the compiler would have the ability to short circuit bitwise comparison. So it doesn't matter if value is 0, 1 or any other value, bitwise OR by compiler cannot be made quicker than assembly command of doing bitwise OR by assembly command.

- Ritwik July 21, 2014 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

The interviewer is really out of touch. Any compiler worth it's salt would optimize that check away to a single jmp. The constant you have there is irrelevant.

- Anonymous July 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

// here is a program that i made to test this thing

#include <stdio.h>
int main()
{int a=0,count=0;//try to change a's values in consecutive runs of the program,once 0 and //once non zero so that both the whle loops gets a chance to execute
if(a==0)
{

while(1&&count<=1000)
{
printf("testing your query");
count++;
}
}
else
{

while(2&&count<=1000)
{


printf("testing your query");

count++;
}
}
return 0;
}
//running this program, consecutively with diffrent a's value i found out that while(2) was //faster than while(1)

- rex.rishabh801 July 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Time the programs in RTOS like MQX to see if there is any difference

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

If we write code using while(1) and while(2) and generate their assembly instructions (without using any compiler optimization options), both assembly turn out to be the same. Furthermore, if optimization options are added while compiling, both will get converted to the same set of assembly instructions. Thus it shouldn't matter which one is used.

Note: This is not the case in all scenarios. Ex - ++i is faster than i++ (check out the assembly, latter one has one extra instruction).

- sweekrut.joshi September 26, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I executed the following code using clock function and it gave me the following result. Based on this the result is while(1) is faster.

#include <stdio.h>
#include <time.h>

int checkFaster()
{
	int a=1;
	clock_t begin,end;
	while(a)
	{
		begin=clock();
		a=0;
	}
	end=clock();
	double time_spent1=(double)(end-begin)/CLOCKS_PER_SEC;
	a=2;
	while(a)
	{
		begin=clock();
		a=0;
	}
	end=clock();
	double time_spent2=(double)(end-begin)/CLOCKS_PER_SEC;
	return (time_spent1>time_spent2?1:0);
}
int main()
{
	if(checkFaster())
		printf("No while2 is faster");
	else
		printf("Yes while1 is faster");
}

- vgeek July 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't think we can determine this way... On a multi-threaded machine there can be X context-switches while executing loop1 & Y context switches while executing loop2... and this difference will be crucial than anything else.
If you execute this program multiple times... you will get different results.

- Rajesh July 30, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 3 vote

Both loops are infinite loops i.e both will take infinite time. I can't deduce which is smaller infinite1 and infinite2.

- Anonymous July 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The question is the evaluation of the expressions regardless of what is going on in the loop itself, i guess.

- oolive35 July 28, 2014 | 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