Skip to main content

C Type Casting

TYPE CASTING

What is Type Casting

The process of converting one predefined datatype into another is called type casting.
Syntax:-
(datatype)value;

C programming provide 2 types of type casting.




Note:- If we are put a char (character datatype) so its print is ASCII  Code.

1.Implicit Type Casting:-In  C language datatype can directly convert into one to another by compiler without user interface is known as implicit type casting. In this casting the lower data type is automatically converted into higher datatype. It is also known as promotion of datatype.
Example:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int x= 10;  //integer x
char y= 'a'; //character y,  ASCII value of 'a' is 97
// y implicitly converted to int .ASCII 
x =x+y;

float z =x + 2.0; // x is implicitly converted to float
printf("x = %d, z= %f", x, z);
getch();
}

Output:
x=107, y=109.00000

2.Explicit Type Casting:- In this type of type casting this is not perform by compiler but explicit specify by user.And explicit type casting higher datatype is converted into lower datatype.

Example:
#include<stdio.h>#include<conio.h>
void main()
{
double x=2.2;
int sum=(int) x+3; //Explicit casting from double to int
printf("sum =%d",sum);
getch();
}
output:
sum =5

                               WAITING FOR NEXT TOPIC

Comments

Popular posts from this blog

Rapid View Of Technology

  Currently Running Top 10 Programming Languages C programming language                         C language is the most popular and and widely used programming language.The C language is developed in 1972 by  Dennis Ritchie at bell laboratories of AT&T American Telephone & Telegraph, located in the U.S.A . C language is also knows as mother and structured programming language.C language is a basic language of all other languages. C++ programming language                                 C++ is object oriented programming language. C++ programming language was developed in 1980 by Bjarne Stroustrup  at bell laboratories of AT&T,located in U.S.A  . C++ is totally based on oops concept. HTML                              ...

Let's Be Technical

.   Programming Languages And There       Importance       Before you know about programming  language  we  must  know about languages. the language is a communication medium why which we can understand other person the language way of the transformation of various ideas and thoughts among people. After this  now we  know about programming language a programming language is a formal language, which comprises a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms. Most programming languages consist of instructions for computers. How its Importance of Programming Language Important in your daily life we use various device & tools that are works one the programming language like microwave ,ATM, Lift etc.  Programming language is important  because it define semantics and grammar which allow the pro...

C Language Tutorial

C Programming Language Tutorial        What is C Programming                              C Language is most popular and widely used programming language. C language is basic language of all other programming languages so also knows as mother language. that directly interact with the hardware devices like kernel and drivers. C is a Procedural language because solve the programming problem in step by step.  C language  break the program into function. C is a Structured language because break a program into several parts and blocks so that easy to understand this program.and break the program into several parts and blocks using function. C is a Mother language because base for other programming language.C language is also considered a several concepts like function, constructor, pointer etc. C is a Mid -level language bcz consider the feature of low-level and high-level p...