Qualcomm Interview Question Software Engineer / Developers




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

http://www.codeguru.com/forum/archive/index.php/t-341247.html

#include <stdio.h>

int main()
{
unsigned int n = 1;
char *p;

p = (char*)&n;
if (*p == 1)
printf("Little Endian\n");
else if (*(p + sizeof(int) - 1) == 1)
printf("Big Endian\n");
else
printf("What the crap?\n");

return 0;

- kichi on September 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice

- biren on November 20, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int num=1;
if(*(char*)&num==1)
printf("Little Endian");
else
printf("Big Endian");

- Nishant on October 07, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nishant's answer can be found in C Programming FAQs. In addition to his answer, FAQ has the union version.

union {
int i;
char c[size(int)];
} x;

x.i = 1;
if (x.c[0] == 1)
printf("Little-endian\n");
else
printf("Big-endian\n");

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

unsigned int* x;
unsigned char *y;
*x = 0x00FF;
y=(char*)x;
if(*y == 0xFF)
//Little Endian
else
//Big Endian

- Anonymous on December 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int x = 0x1;
printf("\n\n%s\n\n", *((char*)&x) ? "Little Endian" : "BIG Endian");

- Amit Kumar on March 22, 2013 | Flag Reply


Add a Comment
Name:

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

Books

is a comprehensive book walking you through 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