20 June, 2017

Experiments in C

So i had a holliday. I've programmed for years, but strangely enough never in C. Why not try it out? I used:


  • gcc as a compiler
  • nano as the editor
So much for the software architecture. I followed these tutorials, and found that the learning curve to C is akin to PHP and JavaScript. The variables are defined in a different way. But loops are pretty much the same thing. Here's a sample from one of the tutorials.

#include
 
int main () {

   int a;
   /* for loop execution */
   for( a = 10; a < 20; a = a + 1 ){
      printf("value of a: %d\n", a);
   }
 
   return 0;
}

The main difference is compiling. So save the code above in say myForLoop.c. Then compile the file, like this:

# gcc -o myForLoop myForLoop.c

Now you can execute the file in a Linux terminal:

# ./myForLoop


No comments: