Skip to main content

type casting in C. - computer science fundamentals tutorial

Typecasting in C

Typecasting is also known as "forced conversion".
It refers to changing variable one data type to another data type.
         Typecasting in can be certified into following two types: -
1) Implicit type casting.
2) Explicit type casting.


Implicit type casting: -
It is also known as "Automatic type conversion".
It is done by compiler on its own without any external trigger from user.
Generally takes place when in an expression more than one data type is present in such condition. Type conversion take places to avoid data lose.
Example: -
#include<stdio.h>
main()
{
  char y = 'a';
  int b = y;
printf("%c",y);
printf("%d",b);
}
Explicit Type casting: -
This process also called 'Type casting' and it is user defined. Here the user can type cast the result to make it of particular data type.
Example: -

#include<stdio.h>

main()

{

int m=7;

float div = (float)m/2;

printf("div = %d",div);

}

Difference between type casting & type conversion

Difference between type casting & type conversion


Comments

  1. Online learning is an educational mode allowing students to take part in different courses and programs using the internet. In online tuition, students don't need to waste their time going to the lecture halls or classrooms, rather they can decide to learn whatever from any part of the world. For online tuitions you can call - +91-9654271931.

    ReplyDelete
  2. Online learning is an educational mode allowing students to take part in different courses and programs using the internet. In online tuition, students don't need to waste their time going to the lecture halls or classrooms, rather they can decide to learn whatever from any part of the world. For online tuitions you can call - +91-9654271931.

    ReplyDelete

Post a Comment

please subscribe my blog and let me suggest how I improve this site

Popular posts from this blog

Minterm and maxterm in Digital logic design - Computer Science fundamentals tutorial

Minterm and Maxterm First thing to know before we proceed   towards   what is ‘minterm’ and ‘maxterm’ we have to know the sum of product and product of sum. Sum of product: - The logical sum of two or more logical product term is called sum of products expression. It is basically an OR operation of AND operated variables such as Y = AB+BC+ABC Product of Sum: - The logical product of two or more logical sum term is called product of sums expressions. It is basically an AND operation of OR operated variables such as Y = (A+B).(B+C).(A+B+C) Minterm: - Product term containing all the k variables of the functions is either complimented or uncomplimented form is Minterm. Canonical form of sum of product: - It is defined as the logical sum of all the minterms derived from the rows of a truth table for which value of the function is 1. It is called a minterm canonical form. The canonical sum of product expression can be given in a compact form by lis...

Solve-write C program to find biggest number from three number by using nested if statement

          C program to find biggest number from three number                                                by using                                                                 nested if statement Problem Description This program takes the 3 numbers and finds the biggest among all. Problem Solution 1. Take the three numbers as input. 2. Check the first number if it greater than other two. 3. Repeat the step 2 for other two numbers. 4. Print the number which is greater among all and exit. Program codes:- here the program of finding biggest of three number run this in your Linux, DEV C++,turbo c++ #include<stdio.h> main() { int num1,num2,num3,big;   ...

Solve-write C program to find grade of student by using nested else-if statement

C program to find grade of student by using nested else-if statement Problem Description This program take input as your number then show your grade. Problem Solution 1. enter your marks as input. 2. then check your marks with 'If' block's condition. if it satisfied then show your grade as output. 3. if it not satisfied then it checks with all else-if block's condition repeatedly. 4. print the grade according to your given marks as input and exit. Program codes:-   #include<stdio.h> main() { int n; printf("\n enter the marks:"); scanf("%d",&n); if(n>89) printf("O"); else if(n>79) printf("E"); else if(n>69) printf("A"); else if(n>59) printf("B"); else if(n>49) printf("C"); else if(n>39) printf("D"); else printf("F"); } Program explanation:- 1. enter your marks. for example we take 70 . ...