answersLogoWhite

0

Malloc is a memory allocation. You specify the amount of memory you need and are given a pointer to that much memory. It doesn't "assign" anything to that value, it just gives you a pointer. At that point you should put whatever you want in there.

User Avatar

Wiki User

18y ago

What else can I help you with?

Related Questions

Could calloc assign memory for object?

yes,it will create memory


What is the difference between malloc and new other than syntax?

Click on the link to your right for the answer.Answerboth malloc and new functions are used for dynamic memory allocations and the basic difference is: malloc requires a special "typecasting" when it allocates memory for eg. if the pointer used is the char pointer then after the processor allocates memory then this allocated memory needs to be typecasted to char pointer i.e (char*).but new does not requires any typecasting. Also, free is the keyword used to free the memory while using malloc and delete the keyword to free memory while using new, otherwise this will lead the memory leak. AnswerBesides the basic syntactical difference: malloc is a C function which will allocate the amount of memory you ask and that's it. new is a C++ operator which will allocate memory AND call the constructor of the class for which's object memory is being allocated. Similarily, free is a C function which will free up the memory allocated. but delete is a C++ operator which will free up the allocated memory AND call the destructor of the object.Answermalloc in a function and new is an operator, and its a good programming practice to use an operator instead of functions, because function itself requires some time to be executed whenever that particular function is called. so the main difference is that we use operators instead of malloc because of the TIME CONSTRAINT. Answer1.malloc requires the type casting during decleration , where as new doesn't needed the type casting during decleration 2. when ever we use new for allocating memory along with this it calls the constructor of the class for which object memory is allocated 3. in case of malloc free is the word used to clear the memory, where as delete is the format used in case of new to free the memory after usage 4. malloc is function, where as new is operator..so the time required for execution is less in case of new (it being a operator) as compared to malloc(it being a function) Answer1. malloc is a function call, while new is an operator. This difference is syntactic; behind the scenes, they both perform pretty much the same work to allocate the memory, and operator new also invokes any required constructors. There is a commonplace urban myth that operators are somehow faster in your code than functions; this is not correct, as any operator (except for mathematical operations that correspond directly to a single machine-code instruction) invocation amounts to a function call in any case. 2. malloc can fail, and returns a NULL pointer if memory is exhausted. Operator new never returns a NULL pointer, but indicates failure by throwing an exception instead. There is also a nothrow() version of operator new, which does return NULL on failure.


How you use malloc function in c?

void* malloc (size_t bytes); This means that malloc takes an argument which is the size of memory to allocate and returns a pointer to that memory which has been allocated. If the return value is NULL, then the request could not be satisfied. Each call to malloc must be balanced with a corresponding call to free, to release the memory. int pa = NULL; pa = (int*) malloc (sizeof(int) * 1000); /* allocate 1000 ints */ if (pa == NULL) throw exception... ... use pa free (pa); pa = NULL;


How can you allocate memory dynamically in c?

char* new_string; // could be any type new_string = (char*) malloc (5120); // allocate memory - typecast is necessary if (new_string == NULL) ... memory exception ... ... use the data ... free (new_string); // release memory when done


What is malloc function in C?

The malloc function is a function used in C/C++ and various other high-level programming languges to add memory to the heap, it is essentially a pointer int* X = malloc(sizeof(int)); Where the parameter to malloc is the number of bytes you want to make room for. Because we are using an integral variable we want to make as much room as an integer takes.


Advantages of new operator over malloc function in c?

1: new operator automatically computes the size of the data object. You need not use the operator sizeof.2: new operator automatically returns the correct pointer type, so that there is no need to use a type cast.3: it is possible to initialize the object while creating the memory space.4: Like any other operator, new and delete can be overloaded.


Does the life policy have to be paid up or have cash value to assign as collateral?

Not nec. You could assign ownership.


How do you turn an Excel cell a colour by pressing one button?

Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.Click on the Fill Color tool icon. You could also write a macro to change the colour and assign it to a button on the worksheet.


Could you please clarify if Delta Airlines does not assign seats in advance for their passengers"?

Yes, Delta Airlines does assign seats in advance for their passengers.


What is the Difference between override and new keyword in C?

An override is the specialisation of a virtual function. The new keyword instantiates an instance of an object in dynamic memory and returns a reference to that object (or null if the object could be instantiated). Both are used in C++, but not C.


What is the memory clue of lithosphere?

The memory clue for lithosphere could be "litho" meaning rock or stone, and "sphere" meaning a round object. This can help you remember that the lithosphere is the rigid outer layer of the Earth composed of solid rock.


What numbers could a and b represent?

Any numbers you care to assign to them.