333 views

1 Answer

0 votes
0 votes
In Implicit casting compiler itself solves the issue of casting for example consider the code

int main()

{

int a;//2 bytes

float b;//44 bytes

char c;//1 byte

}

now if we write b=c means we want to store 1 byte of data in 4byte, we can do so but 3bytes will be wasted since there is no  data lost here and generally we do not bother about memory,so there is no issue in this....but compiler would not accept this sso compiler itself do type casting like this b=(float)c....this is called implicit type casting.

Now consider another case suppose we write c=b;means we want to store 4bytes in 1byte,if we do so then there iss data loss so some compilers will give an error message,then user have to do typecasting himself/herself this is called explicit typ casting.For example: c=(char)b but some data will be lost

Related questions

0 votes
0 votes
0 answers
1
garvit_vijai asked Sep 2, 2018
712 views
Please explain the output for the following program: #include<stdio.h>int main() { int i = 100; int *a = &i; float *f = (float *)a; (*f)++; pri...
1 votes
1 votes
1 answer
2
Jaspreet Kaur Bains asked Jan 27, 2018
362 views
what is the meaning of k= (char *) (i*j)it will return k =(char *) (300)
1 votes
1 votes
1 answer
3
srestha asked Jul 27, 2017
418 views
Analyze what is happening and why?int *ptr=(int*)0X12341230; int *ptr2=((int*)(((char*)ptr)+1));char *ptr=(char*) 0X12341230; void *ptr2=ptr+1;
3 votes
3 votes
2 answers
4