Computer Programming C Laboratory: Unions C Programs

C Program to altering the allocated memory

Dynamic Memory Allocation - C Programming

C Program to altering the allocated memory.

* C Program to altering the allocated memory */

#include <stdio.h>

#include <stdlib.h>

main()

{

char *p; /**p is a pointer variables */

p=(char *)malloc(6); /* malloc() allocate memory to variables */

strcpy(p, "MADRAS"); /* string copy */

printf("Memory contains: %s\n",p)

p=(char *)realloc(p, 7)   /reallocation */

strcpy (p, "CHENNAI");   /* string copy */

printf("Memory now contains: %s\n", p);

free (p); /* Releasing memory*/

free(p);

} /* main */

OUTPUT

Memory contains: MADRAS

Memory now contains: CHENNAI

EXPLANATION: The function malloc() function 6 bytes are allocated to character pointer p. The character pointer is initialised with string MADRAS. To store more than 6 characters, we need to allocate more bytes to pointer 'p'. Using realloc() function memory, allocation takes place. After reallocation the pointer contains 7 bytes. The pointer p is again initialised with CHENNAI. The output display contents of p before and after reallocation. The free() function release the memory allocation.

Computer Programming C Laboratory: Unions C Programs : Tag: C Programming : - C Program to altering the allocated memory


Computer Programming C Laboratory: Unions C Programs



Under Subject


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