What is the difference between stdin and STDIN_FILENO?

后端 未结 4 2002
悲&欢浪女
悲&欢浪女 2020-12-24 00:58

What is the practical difference, if any, between stdin and STDIN_FILENO in C?

4条回答
  •  醉梦人生
    2020-12-24 01:40

    stdin : 1. A file pointer (* FILE) 2. The file descriptor table holds its address when process is created. 3. present in /usr/include/stdio.h

    STDIN_FILENO : 1. It is a macro 2. Its nothing but an array index of a file descriptor table (default 0). 3.present in /usr/include/unistd.h

    Could be more clear by following code.

    #include 
    #include 
    int main() 
    {    
         printf("%d\t\t%p ----- ",STDIN_FILENO,stdin);
    
    return 0; 
    } 
    

提交回复
热议问题