What are variables and constant?

 

fig:- variable and constant

If a variable doesn’t change the value during the execution is called a constant variable, whereas the variable that changes the value during the execution of the program is called a variable. constant can be divided into 2 parts they are:-  

real constant 
12.5 
70.55 
23.555 
constants 
numeric constants 
intiger constant 
10 
12 
-20 
character constant 
string char 
constant 
"hello" 
'123" 
"exa@gmail.com" 
single char 
constant
fig: - Types of variable 

A set of characters that is enclosed between the single quote ' ' is known as a single character constant A set of characters that is enclosed between the double quote " " is known as string character constant. they are also called a group of characters. Those values that are in number except the point are called integer numbers.  Those value that is in point for e.g. 11.5, 25.55, etc. is called real numbers. The real number is of two types they are  Floating number  Double number. 

 

Assigning value of a variable on c 

Assignment operators are used to assigning the value in the operator.  

Syntax 

Int variable  = 10;  // here the value of 10 is assign in variable  

Similarly, we can read the data from keyboard. For that we will use scanf function  

Syntax  

scanf ("control string", &variable1, &variable2); 

%d = for int  

%c = for char  

%f = for float  

%s = for string  

 code  


#include <stdio.h>
#include <conio.h>
void main()
  {
    int a, b;
    clrscr();
    printf("enter first value: ");
    scanf("%d", &a); // it is taking a first value from a user.
    printf("enter second value: ");
    scanf("%d", &b); // it is taking a second value from a user.
    getch();
  }

0 Comments