I found this story on Futility Closet's blog here. The original source was E. Shelton's The Book of Battles (1867).
It was customary with Frederick the Great of Prussia, whenever a new soldier appeared in his guards, to ask him three questions–viz., ‘How old are you? How long have you been in my service? Are you satisfied with your pay and treatment?’
It happened that a young soldier, born in France, and who had served in his own country, desired to enlist into the Prussian service, and his figure was such as to cause him immediately to be accepted. He was totally ignorant of the German language, but his captain gave him notice that the King would question him in that language the first time he saw him, and therefore cautioned him to learn by heart the three answers he was to give.
The soldier learned them by the next day, and as soon as he appeared in the ranks Frederick came up to interrogate him. His Majesty, however, happened to begin with the second question first, and asked him, ‘How long have you been in my service?’
‘Twenty-one years,’ answered the soldier.
The king, struck with his youth, which plainly indicated he had not borne a musket near so long as that, said to him, much astonished, ‘How old are you?’
‘One year, an’t please your Majesty.’
Frederick, still more astonished, cried, ‘You or I must certainly be bereft of our senses.’
The soldier, who took this for the third question, replied firmly, ‘Both, an’t please your Majesty.’
‘This is the first time I ever was treated as a madman at the head of my army,’ rejoined Frederick.
The soldier, who had exhausted his stock of German, stood silent; and when the king again addressed him, in order to penetrate the mystery, the soldier told him in French that he did not understand a word of German. The king laughed heartily, and after exhorting him to perform his duty, left him.