C Unit 4
C Unit 4
have any name that is legal for other variable and it is declared in the
same fashion like other
Features of pointers:
Pointer Declaration:
(or)
datatype * identifier;
Example: int* a;
float* f;
char* y;
Program:
#include<stdio.h>
int main()
int a;
int* pa;
a = 10;
pa = &a;
Output:
2000
2000
10
10
10
3000
time.
calloc and realloc are used for memory allocation. The fourth, free(), is
used to return memory
The malloc function allocates a block of memory that contains the number
of bytes specified in
its parameter. It returns a void pointer to the first byte of the allocated
memory. If it is not
dependent value.
Program:
#include <stdlib.h>
int main()
scanf("%d", &n);
if(ptr == NULL)
exit(0);
return 0;
Output:
Enter elements: 6 5 4 3 2
Sum = 20
#include <stdio.h>
#include <stdlib.h>
int main()
scanf("%d", &n);
if(ptr == NULL)
exit(0);
return 0;
Output:
Enter elements: 6 5 4 3 2
Sum = 20
This function reallocates the main memory. This is needed as and when
allocated memory is different
from the required memory. It returns the address of the reallocated block,
which can be different from