Topic : C++ for Dumies
Author : Randy Nixon
Page : 1 Next >>
Go to page :


Welcome to the nifty world of C programming. Well I'm starting the whole thing over my friends and it will be better this time. Not only will these tutorials be a little more indepth then the previous, but it will also feature eye popping special effects, thx sound, and a special guest appearance by Jennifer Love Hewitt.
History of C

"Hey Dennis, why don't you make a programming language for unix."
"Okay Brian, but you have to help me write the book for it."
"No problem man!"
"Pass the twinkies my brutha."
"Dude I think we're out of twinkies."
"WHAT!!!! You mean to tell me that here in Bell Labs, where we created the transistor, Unix, and the 10 cent a minute long distance dialing plan we can't keep a steady supply of twinkies!"

C was brought to us by those fine people at Bell Labs. You know those at&t people? They had themseves this Operating System called Unix, that needed a programming language. They made it, and since the previous version was called B, they decided to call it C for obvious reasons. No, there was never an A programming language. I say that so you won't embarass your self on an IRC, dang those guys can be brutal. It was written by this guy named Dennis Ritchie. The B in B stood for Bell by the way. So if your ever on jeapordy, now you know.

The workings of C

C is a compiled language. In your cooky compiler it takes the C "code" that you write and breaks it down into these itsy, bitsy, teenie, weenie, 1's and 0's. This is what the computer understands. 1's and 0's. This is called machine language. I still find it amazing that for all the power that a computer has it's just working off a base 2 number system. Wouldn't it be different if humans used base 2? In the lottery you'd only have 0 and 1 too choose from. Roulette would be like, "C'MON 1...C'MON 1....OHHHHHHHH!!!!!" After you compile your source code a thing called an object file is created. Afterwards, if it is brave and it's heart remains pure it is ran through the linker which turns it into an excecutable file. Let's write a simple C program shall we? Don't worry if you don't understand everything I'm about to say. Just copy the source code, I'll break down all lines of code. Do not use capital letters!!!!!! !! Do not copy and paste this code!!!! The < stdio.h > is confusing to your browser, since it looks, smells, and tastes like an html tag. I had to use some spaces. So if you cut and paste it will not work!!! SO there!!!!

#include < stdio.h >
main ( )
printf ("Goodbye Cruel World!!!!");
return (0);

Compile and run. You should get something like Goodbye Cruel World!!!! on your screen.

1st line
This stdio.h stands for standard input output header. Basically the code is "telling" your computer to use a certain command that is found in the stdio.h "file". There are a lot of "#include" files and they all have these wild commands in them, that you can access using the #include thingee.

2nd line
main ( )

This is the main function. There are many functions and all will have to do battle to be worthy of the title main. Okay all joking aside, in C you can have a lot of different functions. These can be titled; main ( ), function1 ( ), function2 ( ), and so on. What you have typed has but one function in it that will do your bidding. It's really not important that you know all of this in your infant stage, but I mention it anyways.

3rd line
This is the all important curly bracket. It is used to seperate "blocks of code" from each other and keep them from fighting each other. Just Kidding.

4th line
printf ("Goodbye Cruel World!!!!");
This is the printf command. It "hides" in the stdio.h file and waits to be called. And now in this line we use it. The printf commands stands for "print format." It is not print function as some believe. It bascially takes the text within the quotation marks and displays it on the screen. "Hey Digital you used capitals." Arrrgghh caught red handed. It won't affect C's case sensitive nature if you use it in this case. "Why does it display on the monitor digital?" Well son, way back in the day before monitors they used teletype (ancient printer) machines to display stuff from the computer. No games back then, too much paper. All printf does is take the stuff you want written and puts it on the screen. YOU MUST ENCLOSE WHAT YOU WANT WRITTEN ON THE SCREEN IN QUOTATION MARKS AND PARENTHESIS! YOU MUST ALSO END THE LINE WIT A SEMI COLON! DO NOT QUESTION IT, JUST DO IT!

5th line
return (0)
This is way too ahead of you at this critical jucture of your C writing career. It returns a value of 0 back to your....see! I can tell your snoozing off already. Just kidding. I'll explain it all later!

6th line
You are enclosing your block of code so it won't get into a fight. Just kidding. Here is where you end this block of code.

So now you've written your first C program. Compile it and run it. Bask in the glory of your accomplishment. Savor this moment young jedi for things get a whole lot more complicated in the future.

"Say digital what if I have more to say?" Good question. 1 line sentences just aren't sexy in our complicated world. Let's add a second line of text by using the newline escape character.

#include < stdio.h >
main ( )
printf ("I fart in your general direction!!!!!!\n");
printf ("Your father was a hamster and \n");
printf ("your mother smelled of elkenberries!!!!!");
return (0);

So here you go. Compile this bad boy and run it. You should get a similar output, but with 3 lines of text. Whenever you use a front slash the compiler says, "Oh my gosh and escape sequence!!!" The printf ignores the n, cuz it has been identified in such a manner.
Ahhhh, the assertation of knowledge. Weeeeeeell, that's all for now folks! I'll see you wacky internet people later - Digitalscribe


Greetings C people welcome to the 2nd installment in my soon to be famous C tutorials. We will be going into variables in this section. Variables are veeeery important in programming. Pay close attention to this chapter kiddies for it you won't get by without it.
What is a variable?

We all know how to add right? 2+2=4? Suppose for an instant though that we wanted write a formula on how to add to someone who had no concept of it. Like say...someone who works for the IRS. We could right it as a+b=c. Now, that lovable IRS guy could write it down and consult it when he forgets how to add. The A, B, and C are variables. Mister IRS has lots of different numbers other then 2 and 4 to deal with it and he can substite those numbers in the place of A,B, or C. "Let's see A = 3, B = 4, so C will equal 7!!!!, Ha and those guys in college mocked me when I decided to work for the government!!!" You can plug any formula you want into a computer; OHM'S LAW E=IR, etc. I know that last sentence wasn't necessary I just want to impress people with the fact I know OHM'S LAW.

All a variable is in our field is just a place set apart in a computers memory to hold a changing value. This is very useful, for it helps those hard working scientists do complex math, leaving plenty of time to eat nachos and watch star trek. Now don't shriek when you see all these numbers, doing math is simple with computers because the computer does all the work!

There are many different types of variables. Each "variable type" has a different range of values. You can only fit oh so much stuff into one variable type! Here are 4 of these variable types;

int - interger/ range = -32768 to +32767/ storage required = 2 bytes

long - long interger/ range = -2147483648 to +2147483647/ storage required = 4 bytes

float- floating point interger/ range = 3.4*10ex38 to 3.4*10ex-38/storage required 8 bytes

It's not a necessity that you memorize these types just yet. I recommend that you learn them through use. To use variables in this section, we will be using the scanf command. The scanf (scan function) basically reads your keyboard for a specific type of input. It stops scanning when you press the enter key. I'll explain more after you write the program.

We'll also using C's operators. An operator is just a cooky word for mathmatical doodad or symbol. The 4 we'll be using is (now pay attention IRS!) + for addition, - for subtraction, * for multiplication, and finally / for division. We

Page : 1 Next >>