Modulo Math

Variables

C Keywords

There are 40 words in C that you cannot use for naming variables of functions. These words are called Keywords, and you can find a complete list of them on the Basic Syntax webpage. Here are a few examples: int, float, char, if, else, do, while, for, switch, case, break, void.

What happens if you set a variable to nothing?

What would be the output of this code?

int x;
printf(“The number is: %d”, x);

This code would output Garbage, because we did not give x a value. It would look like this:

The number is: 3486543245

You should always stop this from happening by giving a value to a variable when you create it, like this:

int x;
printf(“The number is: %d”, x);

Other types

There are other types besides int, char and float. The list of them is on the Variables page.

Strings

Read the page about arrays and the page about strings. Also, remember that Strings are not like the other types (int, float and char). Strings are really arrays of type char.

Also, remember what strings look like in the computer’s memory:

0

1

2

3

4

5

6

7

'C'

'h'

'r'

'i'

's'

'\0'

'\0'

'\0'

Escape characters

We’ve learned about ‘\n’, ‘\0’ and ‘\t’. In C these are called escape characters. Escape characters let you talk about characters that are hard to show. For example:

\u - for writing UNICODE characters (like Thai letters)

\f - Line feed, a little bit like ‘\n’

\” - Quotes, for when you want quotes inside of a string, like this “I read the book \”Harry Potter\” by J.K. Rowling”

\ - Backslash, in case you want a real backslash in your string.

What should I do after this class?

I'm very proud that you've all learned to program in C, which is a very hard language.

If you liked programming, but you thought C was very hard, there are other languages you should try.

The Language Python is very easy to read and write. Here is the Hello World program for Python:

print "Hello World!"

It has no main() function, no brackets {}, no semicolons and no weird symbols. Here's an if statement: