Some general remarks on compilation

Use an editor (for example, emacs) to create a C source code file foo.c.

Compile the source file by issuing the command cc foo.c in an xterm window. If there are no errors in your code, this creates a binary a.out. You execute the binary by issuing the command a.out in an xterm window.

If you want to name the binary foo, compile the source with the command cc foo.c -o foo . You execute this binary by issuing the command foo in an xterm window.


Loops


Compile and run the attached examples. Modify them and study the output.

The text between /* and */ is a comment. The compiler ignores it.


First Programs


/* hello.c */

#include <stdio.h>

int main() {
   printf("Hello!\n");
}



/* hello1.c */

#include <stdio.h>

int main() {
   printf("Hello!\n");
   printf("Hello!\n");
   printf("Hello!\n");
}



/* hello2.c*/

#include <stdio.h>

int main() {
  int i;

   for(i=1; i < 10; i = i+1) {
     printf("%d. Hello!\n",i);
   }
}


Some tips


Comments:
/* This is a comment. */
Formatting with the printf command: