Variable contains a value which changes its value during program execution.
Syntax:- <datatype> <variablename>;
Ex:- int a;
How to declare a character variable?
Ex:- char b;
How to declare a float variable?
Ex:- float c;
How to declare double variable?
Ex:- double d;
How to declare long double variable?
long double k;
How to declare unsigned int variable?
Ex:- unsigned int e;
How to declare long int variable?
Ex:- long int f;
How to declare unsinged long int variable?
Ex:- unsigned long int g;
How to declare string Variable?
Syntax:-
<datatype> <variablename>[size];
Ex:- char s[10];
<variable>=<value>;
How to assign value to the integer variable?
a=10;
How to assign value to the character variable?
b=‘s’;
How to assign value to the float variable?
c=12.4f;
How to assign value to the double variable?
d=45.5;
How to assign value to the string variable?
String variable initialization is not possible.
How to assign value to the unsigned int variable?
e=60000;
How to assign value to the long int variable?
f=100000;
How to assign value to the unsigned long int variable?
g=300000;
How to assign value to the long double variable?
k=567.345l;
Declaration, initialization and printing of integer variable.
output:
Declaration, initialization and printing of character variable.
<datatype> <variablename>=<value>;
int z=10;
Write a program declaration cum initialization and printing of student details.
Rules to write variable names
- A variable name contains maximum of 32 characters.
- A variable name includes alphabets and numbers and underscore, but it must start with an alphabet or underscore.
- It cannot accept any special characters, blank spaces except under score( _ ).
- It should not be a Key word (reserve word).
How to declare different datatypes variables
How to declare integer variable?Syntax:- <datatype> <variablename>;
Ex:- int a;
How to declare a character variable?
Ex:- char b;
How to declare a float variable?
Ex:- float c;
How to declare double variable?
Ex:- double d;
How to declare long double variable?
long double k;
How to declare unsigned int variable?
Ex:- unsigned int e;
How to declare long int variable?
Ex:- long int f;
How to declare unsinged long int variable?
Ex:- unsigned long int g;
How to declare string Variable?
Syntax:-
<datatype> <variablename>[size];
Ex:- char s[10];
How to define/ intialize/assign variables?
syntax:-<variable>=<value>;
How to assign value to the integer variable?
a=10;
How to assign value to the character variable?
b=‘s’;
How to assign value to the float variable?
c=12.4f;
How to assign value to the double variable?
d=45.5;
How to assign value to the string variable?
String variable initialization is not possible.
How to assign value to the unsigned int variable?
e=60000;
How to assign value to the long int variable?
f=100000;
How to assign value to the unsigned long int variable?
g=300000;
How to assign value to the long double variable?
k=567.345l;
Declaration, initialization and printing of integer variable.
Declaration, initialization and printing of character variable.
Output
Declaration of character variable, initialization of ascii value and printing of character variable.
output
Declaration cum Initialization (or) Declaration cum
Definition
Syntax:-<datatype> <variablename>=<value>;
int z=10;
char y=‘s’;
float x=5678.54f;
double w=789.456;
long double v=64.456l;
unsigned int u=61000;
unsigned long int t=400000;
long double v=64.456l;
unsigned int u=61000;
unsigned long int t=400000;
char a[10]=“swathi”;
Declaration cum definition is possible for strings and declaration is also possible for strings only initialization for string is not possible.
output:
Write a program declaration cum initialization and printing of employee details.
Write a program declaration cum initialization and printing of student details.
output
Constant
we cannot change the value anywhere in the program.
Declaration cum Initialization
Syntax:
const <datatype> <constantname>=<value>;












No comments:
Post a Comment