It's called CGI - your app writes the HTTP headers then HTML content to standard output and the web server sends it to the browser.

Compiled code can be fast, but the cost of creating an additional process can outweight the benefit from the addtional execution speed.

Code:
#include <stdio.h> 
#include <stdlib.h>

main() {
		char *chRM;
		char *chQS;

		chRM = getenv("HTTP_USER_AGENT");
		
		//check for NULL or we'll get at error with printf
		if (chRM == NULL) {
			chRM = "NONE";
		}

		chQS = getenv("QUERY_STRING");

		if (chQS == NULL) {
			chQS = "NONE";
		}

        printf("Content-type: text/html\n\n");
        printf("<html>\n");
		printf("<head><title>CGI Test</title></head>\n");
		printf("<body>\n");
        printf("<p>Hello World!\n");
		printf("<br><b>HTTP_USER_AGENT:</b> ");
		printf(chRM);
		printf("<br><b>QUERY_STRING:</b> ");
		printf(chQS);
		printf("</p>\n");
		printf("</body>\n");
        printf("</html>\n");
		return 0;
}