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:
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
Post a Comment
Please do not enter any spam link in message.