You need to add slashes as wp_insert_post
will remove them:
$data = array(
'post_content' => '[code]
#include<stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
[/code]',
);
wp_insert_post( wp_slash( $data ) );
Update: After running the above, this is exactly what I get in the editor:
[code]
#include
int main() {
printf("Hello World\n");
return 0;
}
[/code]