SW006014 Microchip Technology, SW006014 Datasheet - Page 102

C COMPILER MPLAB FOR PIC24 MCU

SW006014

Manufacturer Part Number
SW006014
Description
C COMPILER MPLAB FOR PIC24 MCU
Manufacturer
Microchip Technology
Type
MPLAB® C Compilerr
Series
PIC24r
Datasheet

Specifications of SW006014

Supported Families
PIC24
Core Architecture
PIC
Kit Contents
Software And Docs
Mcu Supported Families
PIC24
Tool Function
Compiler
Tool Type
Compiler
Processor Series
PIC24
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
PIC24
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
DS51456E-page 98
calloc
Description:
Include:
Prototype:
Arguments:
Return Value:
Remarks:
Example:
div
Description:
Include:
Prototype:
Arguments:
Return Value:
Remarks:
Allocates an array in memory and initializes the elements to 0.
<stdlib.h>
void *calloc(size_t nelem, size_t size);
nelem
size
Returns a pointer to the allocated space if successful; otherwise,
returns a null pointer.
Memory returned by calloc is aligned correctly for any size data ele-
ment and is initialized to zero.
/* This program allocates memory for the
/* array 'i' of long integers and initializes */
/* them to zero.
#include <stdio.h>
#include <stdlib.h> /* for calloc, free */
int main(void)
{
}
Output:
i[0] = 0
i[1] = 0
i[2] = 0
i[3] = 0
i[4] = 0
Calculates the quotient and remainder of two numbers
<stdlib.h>
div_t div(int numer, int denom);
numer
denom
Returns the quotient and the remainder.
The returned quotient will have the same sign as the numerator divided
by the denominator. The sign for the remainder will be such that the
quotient times the denominator plus the remainder will equal the
numerator (quot * denom + rem = numer). Division by zero will invoke
the math exception error, which by default, will cause a reset. Write a
math error handler to do something else.
int x;
long *i;
i = (long *)calloc(5, sizeof(long));
if (i != NULL)
{
}
else
for (x = 0; x < 5; x++)
free(i);
printf("Cannot allocate memory\n");
printf("i[%d] = %ld\n", x, i[x]);
number of elements
length of each element
numerator
denominator
/* for printf, NULL */
© 2008 Microchip Technology Inc.
*/
*/

Related parts for SW006014