Interviewer And Interviewee Guide

Professional Device Drivers Interview Questions & Answers:

5. Do you know what is the output of this program?

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

int main()
{
char *ptr;
memcpy(ptr,"google",11);
printf("%sn",ptr);
return 0;
}
a) google
b) segmentation fault
c) syntax error
d) none of the mentioned

b) segmentation fault
Explanation:
Memory must be allocated to pointer "ptr".
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Segmentation fault (core dumped)
[root@localhost google]#

8. Tell me what is the output of this program?

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

int main()
{
char *ptr;
memcpy(ptr,"google",11);
printf("%sn",ptr);
return 0;
}
a) google
b) segmentation fault
c) syntax error
d) none of the mentioned

b) segmentation fault
Explanation:
Memory must be allocated to pointer "ptr".
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Segmentation fault (core dumped)
[root@localhost google]#

9. What is the output of this program?

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

int main()
{
char *ptr;
ptr = (char*)malloc(sizeof(char)*11);
strcpy(ptr,"google");
printf("%dn",*ptr);
return 0;
}
a) s
b) google
c) 115
d) segmentation fault

c) 115
Explanation:
This program will print the equivalent decimal value at location pointed by "ptr".
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
115
[root@localhost google]#

Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.