C

Saturday, 8 July 2017

Program to demonstrate dynamic memory allocation

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
          char *mem_allocation;
          clrscr();
          mem_allocation= malloc( 20* sizeof(char));
          if(mem_allocation==NULL)
          {
           printf("couldn't able to allocate requested memory\n");
          }
          else
          {
                   strcpy(mem_allocation,"Besties");
      }
      printf("Dynamically allocated memory                                  content:""%s",mem_allocation);
           free(mem_allocation);

}

No comments:

Post a Comment

Write a program to draw a circle using mid-point circle drawing algorithm.

#include<iostream.h> #include<graphics.h> #include<conio.h> void drawcircle(int x0, int y0, int r) {         ...