The register_chrdev() function in kernel registers a character device:
int register_chrdev(unsigned  int  major,  const  char*name,
 struct file_operations*ops));
If major is 0 the kernel dynamically allocates a major number and the register function returns it.
Now, let's assume a module foo.ko wants to use /dev/foo with a dynamic major number. How does the userspace learn what major number to pass to  mknod to create /dev/foo ?
                        
As soon as a character device gets registered with a dynamic major number, the corresponding information appears in
/proc/devicesand thus can be retrieved by a user-space application/script in order to create an appropriate node.For a better example you may refer to Linux Device Drivers book (3rd edition), for instance, a script to read
/proc/devicesis shown on this page.