Interview Question
Country: United States
is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
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.
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.
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.
Above code will segfault on IA-64, because you missed to include prototype of "malloc()" function. Include "stdlib.h" header file.
- Narendra. July 02, 2012IA-32 is ILP-32 bit model i.e. integer, long and pointers are 32 bit, but IA-64 is LP-64 bit model i.e. long and pointer is 64 bit. In C if prototype of function is not declared , then compiler assumes return value of function is as "int". "malloc" returns "void*" i.e. some address to allocated memory. On IA-32 integer and pointer of same length that's why it will work. But on IA-64 integer is 32-bit and pointer is 64-bit that why in absence of prototype we will get truncated address from malloc() , which is invalid and when we will try to deference that address, result is segmentation fault.
Check below simple program.
#include <errno.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp;
fp = fopen(argv[1], "r");
if (fp == NULL) {
fprintf(stderr, "%s\n", strerror(errno));
return errno;
}
printf("File exist\n");
fclose(fp);
return 0;
}
This code will check whether file given from command line is exist or not. Here i haven't included "string.h" header file(needed for strerror() function). That's why this program will segfault on IA-64, but on IA-32 it will work fine.