Device Drivers Question:

Download Job Interview Questions and Answers PDF

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

Linux Device Drivers Interview Question
Linux Device Drivers Interview Question

Answers:

Answer #1
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]#

Answer #2
103 asci for 'g'

Download Linux Device Drivers Interview Questions And Answers PDF

Previous QuestionNext Question
Which one of the following in true about this program?

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

int main()
{
char *ptr;
printf("%pn",ptr);
ptr = (char *)malloc(sizeof(char));
printf("%pn",ptr);
return 0;
}
a) this program will give segmentation fault
b) this program will print two same values
c) this program has some syntax error
d) none of the mentioned
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