Jul 10
  • A variable name is any combination of 1 to 31 alphabets,digits or underscores.
  • The first character in the variable name must be alphabet or underscore.
  • No commas or blanks are allowed within a variable name.
  • No special symbol other than an underscore can be used in a variable name.
  • The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword,which is not allowed by the computer.

Example

int si_t;

char code;

float sum_1;

char ss_3_hg;

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • MySpace
  • Reddit
  • RSS
  • Twitter

written by Shweta

Jun 23

Variables

As a programmer, you will frequently want your program to “store” a value. For example, if your program requests a value from the user, or if it calculates a value, you will want to  store  it somewhere so you can use it later. The way your program store or remember things is by using variables. For example:

    int b;   //definition

The Above Line "Says I want to create a space for b and that stores an integer value" 
,it will allocate the memory to b and initialize the garbage value that's is why it
is known as variable definition.

//  it is a comment ,which the c compiler will not process and it is known as single Line comment.

Now store a value in variable b which exits in the memory allocated to the variable b
as :

b=5;

 
therefore,we define a variable as an identifier whose value changes from time to time during execution.
It is a named data storage location in computer memory.

All variables have 3 essential attributes
  1. the name.
  2. the value.
  3. the memory,where the value is stored
In C, there are several standard types for variables:
  • int – integer (whole number) values
  • float – floating point values
  • char – single character values (such as “m” or “Z”)

Declaring a Variable :

syntax: data type variable-name;

Example

int a;

char code;

Initializing a Variable :

When variables are declared,values can be assigned to them into two ways:

  1. Within type decleration

example:

int a = 10;

float b= 0.4e-5;

char c= ‘a’;

2.  Using assignment statement

example

int a;

a=10;

float b;

b=0.4e-5;

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Blogplay
  • LinkedIn
  • MySpace
  • Reddit
  • RSS
  • Twitter

written by Shweta \\ tags: