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

Giang Phạm

New member
What is the output of this program?
Code:
   #include<stdio.h>
   #include<fcntl.h>
   int main()
   {
       int fd, count;
       char ch;
       fd = open("123hoidap.txt",O_RDWR|O_CREAT);
       write(fd,"s",1);
       lseek(fd,0,SEEK_SET);
       write(fd,"d",1);
       lseek(fd,0,0);
       read(fd,&ch,1);
       printf("%c\n",ch);
       return 0;
   }
A. d
B. s
C. sd
D. none of the mentioned
 
Answer: d
Explanation: Because of “lseek” system call the character “s” is overwritten by character “d” in the file “123hoidap.txt”.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
d
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top