Linux Search Pattern Question:

Tell us what is the output of this program?

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

int main()
{
int fd, count;
char ch, *buff;
buff = (char *)malloc(sizeof(char)*10);
fd = open("san.c",O_RDONLY);
count = read(fd,buff,5);
printf("%dn",count);
return 0;
}
a) 5
b) 10
c) 0
d) -1

Search Pattern Interview Question
Search Pattern Interview Question

Answer:

a) 5
Explanation:
The "read" system call returns the number of bytes successfully read.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
5
[root@localhost google]#


Previous QuestionNext Question
Do you know what is the output of this program?

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

int main()
{
int fd;
char *buff;
buff = (char *)malloc(sizeof(char)*5);
fd = open("google.txt",O_RDWR|O_CREAT);
write(fd,"Linux",5);
read(fd,buff,5);
printf("%sn",buff);
}
a) it will print nothing
b) it will print the string "Linux"
c) segmentation fault
d) none of the mentioned
What is the output of this program?

#include<stdio.h>
#include<fcntl.h>

int main()
{
int fd, count;
fd = open("san.c",O_RDONLY);
count = write(fd,"Linux",5);
if(count != 5)
perror("write");
return 0;
}
a) it will write the string "Linux" in the beginning of source file "san.c"
b) it will write the string "Linux" in the end of the source file "san.c"
c) segmentation fault
d) none of the mentioned