printf when used for different processes

I am playing with function fork() (creating few processes)and trying to put some output (with process id,child id and so on) to the shell and sometimes i get output for 2 proccesses mixed up on same line. sometimes I would get something like this...

myShell$  ./a.out
proccess1  processID......  parentID......childID
proccess2  processID......  parentID......childID
proccess4  processID......  parentID......childID
proccess3  processID......  parentID......childID
myShell$

You see how order of processes is mixed up..

Is this happening because prinff buffers outputs and doesn't send them to screen right away? Does fprintf buffers as well..

Sometimes i would get something like this.....

myShell$  ./a.out
proccess1  processID......  parentID......childID
proccess2  processID......  parentID......childID
myShell$ proccess3  processID......  parentID......childID
 proccess4  processID......  parentID......childID

Cananyone help me understand what is happening please

You are seeing context switching. Process #13 runs printf code. But it only gets part way through the code and the OS decides to give the cpu to process #82. It printf's more stuff.

That way your output gets jumbled - part from one process, part from others.

It gets technical if you want to prevent that. You need to use an I/O operation that does not interrupt midway, a single call - instead of the 100's of lines of code in printf. write() is what you want.
example:

#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main()
{
    char tmp[64]={0x0};
    pid_t pid=getpid();
    size_t len=0;    
    
    sprintf(tmp,"My pid is %d\n", pid);
    len=strlen(tmp);
    write(1, tmp, len);  // 1 is stdout
    return 0;
}

It looks to me like process 2 printed...Then process 3 was about to print but his time was taken away and given back to the shell(you can see shell prompt in second code example) then time was given back to process 3 which printed and then process 4 printed.