Interviewer And Interviewee Guide

Device Drivers Interview Question:

In this program the two printed memory locations has the difference of ___ bytes.

#include<stdio.h>
#include<stdlib.h>

int main()
{
int *ptr;
ptr = (int*)malloc(sizeof(int)*2);
printf("%pn",ptr);
printf("%pn",ptr+1);
return 0;
}
a) 1
b) 4
c) can not be determined
d) none of the mentioned

Submitted by: Murtaza
b) 4
Explanation:
Pointer will increment by 4 bytes because it is the types of integer.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
0x9b4e008
0x9b4e00c
[root@localhost google]#
Submitted by: Murtaza

Read Online Device Drivers Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.