Interview Question


Country: United States




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

// Off the top of my head. If this crashes, it's SPARC.  Otherwise it's Intel.
int main(void) {
  int x;
  *(((char*)&x)+1)=1;
}

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

uname -a | grep sparc | wc -l

if output =1 it is a sparc machine or else it is a intel machine.

- sumit.sh.133 February 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

x86 - little endian
sparc - big endian

- Himanshu February 15, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int i;
     int testInt=0xff;
     unsigned char *testChar;
     
     testChar = &testInt;
     for (i=1; i<=4; i++)
     {
        printf("value in byte %d is %d\n", i, *testChar);
        testChar++;
     }

- H Patel March 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This might not be as clear. If you use int testInt=0xffee;
Least significant byte = ee
Most significant byte=ff
Now if you print the value at testchar pointer the output, if the machine is not sparc, would be-
value in byte 1 is 238
value in byte 2 is 255

Suggesting that the machine follows little endian format.

- HakunaMatata April 07, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assuming we are running linux

cat /proc/cpuinfo | grep -i Intel

- Satish July 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 #include<stdio.h>
  2 
  3 int main()
  4 
  5 {
  6 
  7     int x =1;
  8 
  9     char *c = (char*)&x;
 10 
 11     if(*c)
 12 
 13         printf("Little endian");
 14 
 15     else
 16 
 17         printf("Big endian");
 18 
 19 }

- sandeepkumar211221 August 16, 2017 | Flag Reply


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