Declaration & Assignments
C Variables
Variables are memory locations(storage area) in C programming language.
The main purpose of variables is to store data in memory for later use. Unlike constants which do not change during the program execution, variables value may change during execution. If you declare a variable in C, that means you are asking to the operating system for reserve a piece of memory with that variable name.
Variable Definition in C
Syntax:
type variable_name;
or
type variable_name, variable_name, variable_name;
Variable Definition and Initialization
Example:
int width, height=5;
char letter='A';
float age, area;
double d;
/* actual initialization */
width = 10;
age = 26.5;
Variable Assignment
Variable assignment is a process of assigning a value to a variable.
Example:
int width = 60;
int age = 31;
There are some rules on choosing variable names
C Program to Print Value of a Variable
Example:
#include<stdio.h>
void main()
{
/* c program to print value of a variable */
int age = 33;
printf("I am %d years old.\n", age);
}
Program Output:
I am 33 years old.
Comments
Post a Comment