What is the output of this program? [code] #include<stdio.h> #include<fcntl.h> int main() { pid_t fd; char ch;

What is the output of this program?
Code:
   #include<stdio.h>
   #include<fcntl.h>
   int main()
   {
       pid_t fd;
       char ch;
       int count;
       fd = open("san.c",O_RDONLY);
       do{
           count = read(fd,&ch,1);
           printf("%c",ch);
       }while(count);
       return 0;
   }
A. it will print nothing
B. it will print the source code of the source file “san.c”
C. segmentation fault
D. none of the mentioned
 
Answer: b
Explanation: none.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
Code:
#include<stdio.h>
#include<fcntl.h>
int main()
{
        int fd, count;
        char ch;
        fd = open("san.c",O_RDONLY);
        do{
                count = read(fd,&ch,1);
                printf("%c",ch);
        }while(count);
}
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top