How pointer variables are initialized ?

How pointer variables are initialized ?

There are 2 main ways to initialize pointer vaiables.These are:

1.Static Memory Allocation(SMA)
2.Dynamic Memory Allocation(DMA)

Some initialization of pointer variables are given below:

1.As Datatype:
  We can initialize pointer variables as   datatype *VariableName(Declaration)
e.g. int *ptr,i;

It can be initialized as
ptr=&i;

2.We can also initialized pointer as:
int i;
int *ptr;
ptr= null;
ptr=&i;

3.Below I have given a eg for you. This example defines weekdays as an array of pointers to string constants. 

static char *weekdays[ ] =
            {
              "Sun", "Mon", "Tue",  "Wed",
              "Thu", "Fri", "Sat"
            };
            





By:Vivek kr. Agarwal
Date:2031-12-08 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related C Subjective Links

C Subjective interview questions and answers for experienced and fresher