How are pointer variables initialized? 

Pointer variable are initialized by one of the following two waysØ                  Static memory allocation Ø                  Dynamic memory allocation

Showing Answers 1 - 3 of 3 Answers

baseersd

  • Mar 19th, 2008
 

Hope this may be the possible answer.


#include<stdio.h>
#define MAX 5
int main()
{
    int p[] = {1,2,3,4,5};//Static initialization
    int *q = NULL;
    int i;

    for(i=0;i<MAX ;i++)    
        printf("%d",p[i]);
        
    q = (int*)malloc(sizeof(int)*MAX );//Malloc initialization will be done with garbage values and calloc will initialize with 0's
    for(i=0;i<MAX ;i++)
    scanf("%d",&q[i]);

        for(i=0;i<MAX ;i++)    
        printf("%d ",q[i]);

    getch();
    return 0;    
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions