Tech Mahindra interview question

C++ basics ,sql queries and a puzzle