Variables

Variables in 'C' : 
  • Variables are used to store a values in a program so that they can be used later. 
  • We can also say variables are names given to memory location which holds some values. 
  • Since 'C' is a compiled language it is strongly typed language meaning is we must declare variable in a program before it's use. 
  • We can assign value to the variable either at a time of declaration or afterwards in a program. 
  • Syntax for variable declaration is :

     data_type variable_name;
                    Or
      data_type variable_name=value;

  • For example: 
        int a; or int a = 15;
Here we are declaring variable a of type integer indicates that a can hold only integer values.

  • When we declare some variable compiler allocates memory for it and store its value at that location.
  • Let's see program to print value and address of a variable 


#include<stdio.h>
int main()
{
  //declaration
    int num;
    num=45;
    printf("Value of num=%d",num);
    printf("Address of num is %d",&num);
    return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.