Académique Documents
Professionnel Documents
Culture Documents
This program calculates the sum of n numbers entered by the user. To perform this task,
memory is dynamically allocated using malloc(), and memory is freed using free()
function.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i, *ptr, sum = 0;
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, num;
float *data;
if(data == NULL)
{
printf("Error!!! memory not allocated.");
exit(0);
}
printf("\n");
#include <stdio.h>
#include <stdlib.h>
/*structure declaration*/
struct student
{
char name[30];
int roll;
float perc;
};
int main()
{
struct student *pstd;
if(pstd==NULL)
{
printf("Insufficient Memory, Exiting... \n");
return 0;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
int n;
char *text;
scanf("%d",&n);
text=(char*)calloc(n,sizeof(char));
gets(text);
/*Free Memory*/
free(text);
return 0;
#include <stdio.h>
#include <stdlib.h>
/*structure declaration*/
struct student
{
char name[30];
int roll;
float perc;
};
int main()
{
struct student *pstd;
int n,i;
if(pstd==NULL)
{
printf("Insufficient Memory, Exiting... \n");
return 0;
}
return 0;
}