by David Hamrick

Home
Links

Starting Out
Compiler
Hello World Program
Comments

Variables
Int, Char, Float

Scanf

Projects
ATM project
Maze project
Unit Conversion project






 


Int, Char, Float

Variables are vital to programming. In a nutshell a variable is a value. Lets go through the 3 basics.

Int - int is a reduced way of saying an integer. Which is a whole number between -32768 to 32767.
Char - char is a reduced way of saying a character. It holds one character.
Float - a Floating Point Number is a number correct to 6 decimal places.

Lets go straight into an example. Its easiest to understand just by seeing.

#include <stdio.h>

int main()
{
  char a; //Variable a is a char
  int s; // Variable s is a int
  float b; //Variable b is a float

  char d = 'd'; // The char d is given the value d
  int r = 32;
  float c = 1.2452;

  char cd, cf; //Declared 2 char variables cd and cf
  return 0;
}

I think all of that is pretty self explanatory. When you declare a variable you can give it a value right away or wait awhile to give it one. But be warned if you try to do anything to that number before its given a value you will get a wierd number. You can also declare more than one variable at the same time as we saw in the char cd, cf; line. They are 2 completely different variables that have nothing to do with eachother except they are both char variables. Now that we are done declaring variables inside of functions lets try doing it outside of a function

#include <stdio.h>
 

int d;
int main()
{
  d = 5; 
  return 0;
}

 

Hosted by www.Geocities.ws

1