By Mohammed Tsjuddin
By Mohammed Tsjuddin
By Mohammed Tsjuddin
BY MOHAMMED TSJUDDIN
C PROGRAMMING
Type casting :
There are two types of type casting.
1)Inmlicit type casting
2)Explicit type casting
Implicit type casting : it is done by compiler
#include<stdio.h>
int main(){
int x = 10; // integer x
char y = 'a'; // character c
// y implicitly converted to int. ASCII
// value of 'a' is 97
x = x + y;
// x is implicitly converted to float
float z = x + 1.0;
printf("x = %d, z = %f", x, z);
return 0;
C PROGRAMMING
Explicit typecasting :
it have to develop by user.
#include<stdio.h>
int main(){
double x = 1.2;
// Explicit conversion from double to int
int sum = (int)x + 1;
printf("sum = %d", sum);
return 0;
}
C PROGRAMMING
Dynamic memory allocation :
The concept of dynamic memory allocation in c language enables the C
programmer to allocate memory at runtime. Dynamic memory
allocation in c language is possible by 4 functions of stdlib.h header file.
1)malloc()
2)calloc()
3)realloc()
4)free()
C PROGRAMMING
malloc() allocates single block of requested memory.
calloc() allocates multiple block of requested memory.
realloc() reallocates the memory occupied by malloc() or calloc()
functions.
free() frees the dynamically allocated memory.
C PROGRAMMING
#include <stdio.h>
#include <stdlib.h>
int main() {
// This pointer will hold the
// base address of the block created
int* ptr;
int n, i;
// Get the number of elements for the array
printf("Enter number of elements:");
scanf("%d",&n);
printf("Entered number of elements: %d\n", n);
free(ptr);
}
return 0;
}