Variable Declaration and Initialization
·
C is a strongly typed
language.
·
Every variable must
be declared, indicating its data type before it can be used.


Examples:
·
int a=10;
·
float pt = 3.14;
·
char ch = ‘X’;
·
int a=10, b=a, c=
a+b;
·
char NameStr[10] =
{“Rajesh”};
·
char SurNameStr[ ] =
{“Mishra”};
·
int NumArr1[5] =
{10,20,30,40,50};
·
int NumArr2[] =
{10,20,30,40,50};
·
int FiveNumArr1[5] =
{0,0,0,0,0};
·
int FiveNumber2[5] =
{0};
·
int MatixA[2][2] =
{{1,2},{3,4}};
·
char
MultiNameStr[3][10] = {“RaM”, “Rama”, “Rajesh”};
Pointer Initialization
Declaration
of C Pointer variable
·
General syntax of pointer
declaration is,
·
datatype
*pointer_name;
·
Data type of a pointer must be same
as the data type of the variable to which the pointer variable is pointing.
·
void type pointer works with all data types, but is not often
used.
·
Here are a few examples:
int *ip // pointer
to integer variable
float *fp;
// pointer to float variable
double *dp;
//
pointer to double variable
char *cp; // pointer
to char variable
Initialization
of C Pointer variable
What is pointer initialization?
·
Pointer
Initialization is the process of assigning address
of a variable to a pointer variable.
·
Pointer variable can only contain address of a variable of the same
data type.
·
In C language address operator &
is used to determine the address of a variable.
#include<stdio.h>
voidmain()
{int a=10;
int*ptr;//pointer declaration
ptr=&a;//pointer initialization
}