Saturday, January 11, 2014


 PROGRAM TO STORE A STRING OF 5 CHARACTERS (DYNAMIC ALLOCATION)

#include<stdio.h>
#include<malloc.h>
main()
{
char *cp;
int i;
cp=(char *)calloc(5,1);
printf("the storage address of memory\n");
printf("Block address :%u\n",cp);
printf("enter the string having 5 characters\n");
for(i=1;i<=5;i++)
{
*cp++=getchar();
printf("the character %d is %c\n",i,*(cp-1));
printf("it is stored in the address  %u\n",(cp-1));
}
}


"dynamic.c" 18L, 354C                                         10,1          All


OUTPUT:

"dynamic.c" 18L, 354C written
[staff@linuxserver staff]$ cc dynamic.c
[staff@linuxserver staff]$ ./a.out
the storage address of memory
Block address :134518568
enter the string having 5 characters
nisha
the character 1 is n
it is stored in the address  134518568
the character 2 is i
it is stored in the address  134518569
the character 3 is s
it is stored in the address  134518570
the character 4 is h
it is stored in the address  134518571
the character 5 is a
it is stored in the address  134518572















No comments:

Post a Comment