VARIABLES IN C LANGUAGE
Variables in C
A variable represents a memory location that stores the data. For example: an int variable num has a value 10 (int num = 10), here the variable name is "num" that represents the location in the memory where this value 10 is stored. As the name suggests, the value of a variable can be changed any number of times.
Syntax – Declaring a variable
data_type variable name; For example:
//a variable num of int type
int num;
//two variable ch1 and ch2 of char type
char ch1, ch2;
//three variable x, y and z of float type where y has been
// initialized with a value and other variables x & z are
// un-initialized.
Float x, y=10.5, z;Example: Variables in C
#include <stdio.h>
int main()
{
int num1 = 20, num2 = 50;
char ch = 'A';
float x = 10.5, y = 13.5;
printf("Variable 'ch' value: %c\n", ch);
printf("Variable num1 and num2 values: %d\t%d\n", num1, num2);
printf("Variable x and y values: %f\t%f\n", x, y);
return 0;
}Output:

Comments
Post a Comment