0
#include<stdio.h>
#include<unistd.h>
char *msg1="HELLLO",*msg2="NONONO";//global declaration prints without any garbage value
int main()
{
/*char *msg1="HELLLO",*msg2="NONONO";"global declaration prints with garbage value */
char buf[6];
int file[2],i;
if(pipe(file) < 0)
    printf("\nyou are out");
write(file[1],msg1,6);
write(file[1],msg2,6);
for(i=1;i<=2;i++){
    read(file[0],buf,6);
    printf("\n%s",buf);}
return 0;

}

Output: As Global Variable: HELLLO NONONO

As local variable: HELLLO▒▒▒ NONONO▒▒▒

4

0

Browse other questions tagged or ask your own question.