Computer Programming C Laboratory: Practical C Programs

Write a C program using Memory allocation function

C Program with Algorithm, Flowchart, Output

Simple C Program with Algorithm, Flowchart, Output - Computer Programming - C

Write a program using Memory allocation function.


AIM

To write a program to memory allocation function.


ALGORITHM

Step‒1 : Start

Step-2 : Allocate 10 Bytes to buffer using malloc()

Step‒3 : Check it is NULL

Step-4 : Copy data to allocated buffer

Step-5 : Print buffer contents

Step-6 : Reallocate buffer with 15 Bytes

Step-7 : Check it is NULL

Step-8 : Move data to reallocated buffer

Step‒9 : Print buffer contents

Step-10 : Free up buffer

Step‒11 : Stop


FLOWCHART



PROGRAM

#include<stdio.h>

#include<conio.h>

#define NULL 0

void main()

{

char *buffer;

if((buffer (char*)malloc(10))==NULL)

{

       printf("malloc failed.\n");

       exit(1);

}

printf("Buffer of size %d created \n",msize(buffer));

strcpy(buffer, "BOMBAY");

printf("Buffer contains: %s\n",buffer);

if((buffer == (char*) realloc(buffer, 15))==NULL)

{

        printf("Reallocation failed.\n");

        exit(1);

}

printf(“Buffer size modified.\n");

printf(“Buffer still contains: %s \n",buffer);

strcpy(buffer, "MUMBAI");

printf("Bufer now contains: %s\n",buffer);

free(buffer);

}


OUTPUT

Buffer of size 10 created

Buffer contans BOMABAY

Buffer size modified

Buffer still contains: BOMBAY

Buffer now contains: MUMBAI

 

Computer Programming C Laboratory: Practical C Programs : Tag: C Programming : C Program with Algorithm, Flowchart, Output - Write a C program using Memory allocation function


Computer Programming C Laboratory: Practical C Programs



Under Subject


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation