GeekInterview.com
Series: Subject: Topic:
Question: 484 of 587

How are pointer variables initialized? 

Pointer variable are initialized by one of the following two ways                  Static memory allocation                   Dynamic memory allocation
Asked by: Interview Candidate | Asked on: Mar 6th, 2005
Showing Answers 1 - 1 of 1 Answers
baseersd

Answered On : Mar 19th, 2008

View all answers by baseersd

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;    
}

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.