Skip to content

Tag Archives: C-Dynamic Memory Allocation

Memory is divided into smaller addressable units called bytes. Assume that these are small boxes as bytes. Each byte has its own address as per… Read More
In this article, if memory allocation using new is failed in C++ then how it should be handled? When an object of a class is… Read More
As we know that new is used to create memory dynamically and it is the programmer’s responsibility to delete the memory location explicitly and it… Read More
Data Types Data-type in simple terms gives us information about the type of data. Example, integer, character, etc. Data-types in C language are declarations for the variables.… Read More
Pre-requisite: Dynamic memory allocation in C The “malloc” or “memory allocation” method is used to dynamically allocate a single large block of memory with the… Read More
Memory leakage occurs in C++ when programmers allocates memory by using new keyword and forgets to deallocate the memory by using delete() function or delete[]… Read More
Prerequisite: How to dynamically allocate a 2D array in C? Double pointer: A pointer pointing to another pointer is known as a Double pointer. To… Read More
Dereferencing an unknown memory location : C programmers mostly use scanf() function to take input, but sometimes a small mistake can bring a bug or… Read More
Core Dump/Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.”   When a piece of code tries… Read More
Consider the following program, where are i, j and k are stored in memory? int i; int main() {     int j;     int *k = (int… Read More
What is the problem with following code? #include<stdio.h> int main() {     int *p = (int *)malloc(sizeof(int));        p = NULL;        free(p); } (A) Compiler… Read More
Which of the following is true? (A) “ptr = calloc(m, n)” is equivalent to following ptr = malloc(m * n); (B) “ptr = calloc(m, n)”… Read More
What is the return type of malloc() or calloc() (A) void * (B) Pointer of allocated memory type (C) void ** (D) int * Answer:… Read More
Which of the following is/are true (A) calloc() allocates the memory and also initializes the allocates memory to zero, while memory allocated using malloc() has… Read More
Output? # include<stdio.h> # include<stdlib.h>     void fun(int *a) {     a = (int*)malloc(sizeof(int)); }     int main() {     int *p;     fun(p);     *p = 6;     printf("%d\n",*p);… Read More