40KHz pwm square wave

Shooter please read the OP message he said:-

and can anyone please tell me if we can generate a sine wave of 40KHz via arduino.

And that code is never going to work.