[Solved] Which is better, ch = ‘\n’; write(1, &ch, 1); or putchar(‘\n’);?


The putchar is a library function. It calls the write system call to write the character in stdout.

If we access the system call so many time, the system performance will get slow.

So only, the library functions are implemented.

The library functions for writing, it allocates a buffer, once if the buffer is fulled or flushed then only it calls the write system call to write the contents in stdout.

So, if you want good system performance, you have to use the library functions (putchar).

Is there any need you have the write the output immediately, you can use the write system call.

1

solved Which is better, ch = ‘\n’; write(1, &ch, 1); or putchar(‘\n’);?