Read + Write + Report
Home | Start a blog | About Orble | FAQ | Blogs | Writers | Paid | My Orble | Login
 
Weird and wonderful facts and trivia, useless information, gadgets, idiots, criminals, and heaps of humour - you name it, we've got it!

FIREFOX USERS TAKE NOTE: You may be missing half of the page for some strange reason, so you may want to try another browser to view the site accurately.

Choose categories or enter a term into the search box on the LEFT hand side of the page for other related posts.
Custom Search

C tute 2: variables

July 31st 2006 03:31
Today's lesson is going to introduce variables, which are used to store information within a program. At the moment we will explore three main forms: int, float and char.

Int stands for integer, which basically means any number without decimal points.

Float stands for a floating point number, which basically means a number with decimals.

Char stands for a single character.

Variables can be named anything, but cannot begin with numbers, or be a c keyword.

Defining variables

A variable must be defined before it is used, and this is done as follows:

int variablename;

Multiple variables can be defined at once:

int v1, v2, v3;

It is also possible to give a variable a value at the same time as defining it.

int v1 = 1;

The system for defining variables is the same with other variable types.

Integers can also be defined with other words, like short, long, unsigned short and unsigned long.

Short and long define the number of bytes used to store the integer and signed and unsigned decide whether positive or negative numbers can be stores.

So

unsigned short int v1;

Would define v1 as a short integer that cannot store signs.

Custom data types

You can also define your own data types. For example, rather than writing

unsigned short int v1;

You can define a data type that has these features with the typedef command, which takes the following form:

typedef datatype dataname;

So, in this case it would be:

typedef unsigned short int customtype;

and then to define v1 we would write

customtype v1;

We will discuss custom data types more later, but that is it for today.

Adam

120
Vote


   
subscribe to this blog 


   

   


Add A Comment

To create a fully formatted comment please click here.


CLICK HERE TO LOGIN | CLICK HERE TO REGISTER

Name or Orble Tag
Home Page (optional)
Comments
Bold Italic Underline Strikethrough Separator Left Center Right Separator Quote Insert Link Insert Email
Notify me of replies
Your Email Address
(optional)
(required for reply notification)
Submit
More Posts
1 Posts
4 Posts
2 Posts
683 Posts dating from April 2006
Email Subscription
Receive e-mail notifications of new posts on this blog:
0
Moderated by MelissaA
Copyright © 2012 On Topic Media PTY LTD. All Rights Reserved. Design by Vimu.com.
On Topic Media ZPages: Sydney |  Melbourne |  Brisbane |  London |  Birmingham |  Leeds     [ Advertise ] [ Contact Us ] [ Privacy Policy ]