C

Variables in C Language

A variable is a name that may be used to store a data value.
Unlike constant, variables are changeable, we can change value of a variable during execution of a program.
A programmer can choose a meaningful variable name.
Example : average, height, age, total etc.

Rules to define variable name

  • Variable name must be upto 8 characters.
  • Variable name must not start with a digit.
  • Variable name can consist of alphabets, digits and special symbols like underscore _.
  • Blank or spaces are not allowed in variable name.
  • Keywords are not allowed as variable name.

Declaration of variable

Declaration of variables must be done before they are used in the program. Declaration does two things.

  • It tells the compiler what the variable name is.
  • It specifies what type of data the variable will hold.

Example:

//Write a Program for Addition of two Numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b,sum;    //variable declaration
    a=30;
    b=20;
    sum=a+b;
    printf("Sum is %d",sum);
    getch();
}

Output:

Command Prompt
Sum is 50



Subscribe us on Youtube

Share This Page on

Questions


Rajan | 24-Apr-2016 10:11:39 pm

Hi students i will show you how to download programs without share on fb. step 1 : open developer tools "ctrl+shift+i" step 2 : goto console step3 : type $("pre").html(); step 4 : All Done your program is here :)


No name | 01-May-2016 02:06:12 pm

Hi please check it twice and let me know it is possible right now???


sagar | 19-Jun-2016 02:15:25 am

Hi Rajan It's not fault of the site... It's a fault of Google chrome browser..


ravi kacha | 20-Jun-2016 11:16:22 pm

Yes you are right sagar


Ask Question