What is the output of this program? [code] #include<stdio.h> #include<stdlib.h> #include<string.h> #include<sys/types.h>

Huỳnh Hiền

New member
What is the output of this program?
Code:
   #include<stdio.h>
   #include<stdlib.h>
   #include<string.h>
   #include<sys/types.h>
   #include<sys/ipc.h>
   #include<sys/msg.h>
   struct data_st{
       long int id;
       char buff[11];
   };
   int main()
   {
       int m_id,ret;
       struct data_st data1, data2;
       m_id = msgget((key_t)181,0666|IPC_CREAT);
       if(m_id == -1)
           perror("msgget");
       data1.id = 1;
       strcpy(data1.buff,"123hoidap");
       ret = msgsnd(m_id,&data1,11,0);
       printf("%d\n",ret);
       if(msgrcv(m_id,&data2,11,1,0) == -1)
           perror("msgrcv");
       if(msgctl(m_id,IPC_RMID,0) != 0)
           perror("msgctl");
       return 0;
   }
A. 0
B. 1
C. -1
D. none of the mentioned
 
Answer: a
Explanation: The function msgsnd() returns 0 when there is no error.
Ouptut:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
0
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top