text: Variables, Data Types and I/O in C. Variable Names in C. Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but watch out!! Case matters! C keywords cannot be used as variable.
  Variable Names
  present, hello, y2x3, r2d3, ... /* OK */
  _1993_tar_return /* OK but don’t */
  Hello#there /* illegal */
  double /* shouldn’t work */
  2fartogo /* illegal */
  Suggestions regarding variable names
  Numeric Variable Types
  vcan also just write "short"
  voften the same number of bits as an int
  vcan also just write "long"
  vif int has 32-bits, range from 0..232-1
  valso works with long and short
  DATABytes Required
  The letter x (char) 1
  The number 100 (int) 4
  The number 120.145 (double) 8
  A typical 32-bit machine
  Type Keyword Bytes Range
  character char 1 -128...127
  integer int 4 -2,147,483,648...2,147,438,647
  short integer short 2 -32768...32367
  long integer long 4 -2,147,483,648...2,147,438,647
  long long integer long long 8 -9223372036854775808 …
  9223372036854775807
  unsigned character unsigned char 1 0...255
  unsigned integer unsigned int 2 0...4,294,967,295
  unsigned short integer unsigned short 2 0...65535
  unsigned long integer unsigned long 4 0...4,294,967,295
  single-precision float 4 1.2E-38...3.4E38
  double-precision double 8 2.2E-308...1.8E308
  Specifier Meaning
  %c Single character
  %d Signed decimal integer
  %x Hexadecimal number
  %f Decimal floating point number
  %e Floating point in “scientific notation”
  %s Character string (more on this later)
  %u Unsigned decimal integer
  %% Just print a % sign
  %ld, %lldlong, and long long
  scanf ("%d", &x); /* reads a decimal integer */
  scanf ("%f", &rate); /* reads a floating point value */
  int n1, n2; float f;
  scanf("%d%d%f",&n1,&n2,&f);
  5 10 20.3
  scanf("value=%d,ratio=%f", &value,&ratio);
  value=27,ratio=0.8
  int x=10;
  float y,z=3.14;
  y=(float) x; /* y=10.0 */
  x=(int) z; /* x=3 */
  x=(int) (-z); /* x=-3 -- rounded approaching zero */
  inti;
  short int j=1000;
  i=j*j; /* wrong!!! */
  i=(int)j * (int)j; /* correct */
  char c='a';
  inti;
  i=c; /* i is assigned the ASCII code of ‘a’ */
  inti=5 , j=1;
  float x=1.0 , y;
  y = x / i; /* y = 1.0 / 5.0 */
  y = j / i; /* y = 1 / 5 so y = 0 */
  y = (float) j / i; /* y = 1.0 / 5 */
  /* The cast operator has a higher precedence */
  The sizeof() function returns the number of bytes in a data type.
  int main() {
  printf("Size of char ......... = %2d byte(s)\n", sizeof(char));
  printf("Size of short ........ = %2d byte(s)\n", sizeof(short));
  printf("Size of int ........... = %2d byte(s)\n", sizeof(int));
  printf(“Size of long long …… = %2d byte(s)\n”, sizeof(long long));
  printf("Size of long ......... = %2d byte(s)\n", sizeof(long));
  printf("Size of unsigned char. = %2d byte(s)\n", sizeof (unsigned char));
  printf("Size of unsigned int.. = %2d byte(s)\n", sizeof (unsigned int));
  printf("Size of unsigned short = %2d byte(s)\n", sizeof (unsigned short));
  printf("Size of unsigned long. = %2d byte(s)\n", sizeof (unsigned long));
  printf("Size of float ........ = %2d byte(s)\n", sizeof(float));
  printf("Size of double ....... = %2d byte(s)\n", sizeof(double));
  printf("Size of long double .. = %2d byte(s)\n", sizeof(long double));
  return 0;
  }
  Results of a previous run of this code ...
  Size of char = 1 byte(s)
  Size of short = 2 byte(s)
  Size of int = 4 byte(s)
  Size of long = 4 byte(s)
  Size of long long = 8 byte(s)
  Size of unsigned char = 1 byte(s)
  Size of unsigned int = 4 byte(s)
  Size of unsigned short = 2 byte(s)
  Size of unsigned long = 4 byte(s)
  Size of float = 4 byte(s)
  Size of double = 8 byte(s)
  Size of long double =16 byte(s)
  typedefoldtypenewtype;
  typedef long int32; /* suppose we know an int has 32-bits */
  typedef unsigned char byte; /* create a byte type */
  typedef long double extended;
  typename varname1, varname2, ...;
  int count;
  float a;
  double percent, total;
  unsigned char x,y,z;
  long intaLongInt;
  long AnotherLongInt
  unsigned long a_1, a_2, a_3;
  unsigned long int b_1, b_2, b_3;
  typedef long int32;
  int32 n;
  Initialization
  int count; /* Set aside storage space for count */
  count = 0; /* Store 0 in count */
  int count = 0;
  double percent = 10.0, rate = 0.56;
  unsigned int value = -2500;
  Constants
  const double pi=3.1415926;
  const intmaxlength=2356;
  const intval=(3*7+6)*5;
  Note: simple computed
  values are allowed
  Preprocessor Constants
  #define CONSTNAME literal
  #define PI 3.14159
  #include <stdio.h>
  #define GRAMS_PER_POUND 454
  const int FARFARAWAY = 3000;
  int main ()
  {
  intweight_in_grams, weight_in_pounds;
  intyear_of_birth, age_in_3000;
  printf ("Enter your weight in pounds: ");
  scanf ("%d", &weight_in_pounds);
  printf ("Enter your year of birth: ");
  scanf ("%d", &year_of_birth);
  weight_in_grams = weight_in_pounds * GRAMS_PER_POUND;
  age_in_3000 = FARFARAWAY - year_of_birth;
  printf ("Your weight in grams = %d\n", weight_in_grams);
  printf ("In 3000 you will be %d years old\n", age_in_3000);
  return 0;
  }
  int y=-46;
  char ch='a';
  float PI=3.14159;
  double minusPItimes100 = -3.14159e2