A Little about the blog.....

This blog contains all the interview questions that i face during my interviews with various MNC's. I am trying to post the solutions for almost all the questions and i have covered few important topics which would be frequent topics in interviews. I hope the blog would be useful not only for the job aspirants but also to the one who tries to upgrade his/her knowledge in C and Embedded concepts......

please enter your mail address in the above mail address box to get the immediate updates of the new interview questions.....

Thursday, November 17, 2011

A small example for Dynamic Memory allocation

#include"stdio.h"
#include"conio.h"
#include"stdlib.h"
void main()
{
int* a,n,i;
clrscr();
printf("how many numbers you want to enter");
scanf("%d",&n);
a=(int*)malloc(n*sizeof(int)); // calloc can be used as //a=(int*)calloc(n,sizeof(int));
printf("\nenter the numbers\n");
for(i=0;i {
scanf("%d",a+i);
}
printf("enter a new value for n");
scanf("%d",&n);
a=(int*)realloc(a,n*sizeof(int));
printf("the entered numbers are");
for(i=0;i {
printf("%d\n",*(a+i));
}
getch();
}

No comments:

Post a Comment