C Introduction

C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.

C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Get Started With C

To start using C, you need two things:

C While Loop

Loops

Loops can execute a block of code as long as a specified condition is reached.

Loops are handy because they save time, reduce errors, and they make code more readable.

While Loop

The while loop loops through a block of code as long as a specified condition is true:

#include 

int main() {
  int i = 0;
  
  while (i < 5) {
    printf("%d\n", i);
    i++;
  }
  
  return 0;
}
C Statements

Statements

A computer program is a list of "instructions" to be "executed" by a computer.

In a programming language, these programming instructions are called statements.

The following statement "instructs" the compiler to print the text "Hello World" to the screen:

#include 

int main() {
  printf("Hello World!");
  return 0;
}
C Comments

Comments in C

Comments can be used to explain code, and to make it more readable. It can also be used to prevent execution when testing alternative code.

Comments can be singled-lined or multi-lined. Single-line Comments Single-line comments start with two forward slashes (//). Any text between // and the end of the line is ignored by the compiler (will not be executed). This example uses a single-line comment before a line of code:

#include 

int main() {
  printf("Hello World!"); // This is a comment
  return 0;
}