What is the output of this program? [code] #include<stdio.h> #include<string.h> int main() { int fd[2]; int count;

Kim Thu Đoàn

New member
What is the output of this program?
Code:
   #include<stdio.h>
   #include<string.h>
   int main()
   {
       int fd[2];
       int count;
       char buffer[6];
       if( pipe(fd) != 0)
           perror("pipe");
       memset(buffer,'\0',6);
       count=write(fd[1],"Linux",6);
       read(fd[0],buffer,6);
       printf("%s\n",buffer);
       return 0;put
   }
A. this program will print the string “Linux”
B. this program will print nothing because the buffer is empty
C. segmentation fault
D. none of the mentioned
 
Answer: a
Explanation: The data in buffer is written by the pipe.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
Linux
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top