A colonoscopy is a medical procedure that allows for the examination of the interior lining of the colon and rectum using a flexible tube with a camera called a colonoscope. It is primarily used for the detection and prevention of colorectal cancer and other gastrointestinal diseases.