Exercise 1.1 - testing hello, world

Question

Run the hello, world program on your system. Experiment with leaving out parts of the program, to see what error messages you get.

/* First Program in K&R. print hello,world */

#include <stdio.h>

int main() {
    printf("hello, world\n");
}

Explanation

  1. Leaving out #include<stdio.h>

The program still compiles and it gives the warning stating that it is using a built-in function printf.

helloworld.c:5: warning: incompatible implicit declaration of built-in function ‘printf’
  1. Leaving out int or void or both

The program compiles and runs without any warning. We know that spaces and indentation is not important, so we can strip them out.

  1. The smallest program that compiles with warning, but executes is this.

main(){printf("hello,world\n");}
  1. Any part of the string “hello,worldn” can be left out without any error, just the program output will be different.

  2. Leaving any other part the program will now result in compilation error.

For e.g. After removing ; in the above program, we got the compilation error.

error: expected `;` before the '}' token