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

What is the output of this program?
Code:
    #include<stdio.h>
    #include<fcntl.h>
    int main()
    {
        int fd, fd2, ret;
        fd = open("san.c",O_RDONLY);
        ret = close(fd2);
        printf("%d\n",ret);
    }
A. 0
B. 1
C. -1
D. none of the mentioned
 
Answer: c
Explanation: The “close” system call closes a file descriptor but in the program “fd2” in not a file descriptor. Hence close system call returns -1.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
-1
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top