in Programming in C
767 views
1 vote
1 vote

how can int pointer be used to point to string constant??? even if we consider that address was passed to int pointer then when while(*++p1) is executed it must raise error right bcoz we are using int pointer???

in Programming in C
767 views

4 Comments

By the way arithmetic operation is not allowed between pointers, right????
0
0
no i dont think they are working with ascii value because * not used.
0
0
Undefined behavoir in C because we can,t use  integer pointer to point to a string literal and both integet and char have different alignment requirement .
0
0

1 Answer

0 votes
0 votes
char will be automatically typecasted to int without the loss of data

I think the output will be 3.
edited by

4 Comments

You can't perform multiplication and division on pointers (bcz No meaning ),but you can do addition and subtraction on pointers
2
2
Even one more thing to note;

Addition of two pointers is not allowed. It doesn’t make logical sense to add two pointers because you won’t know what the new address will be. You’ll get a compiler error if you attempt to perform such an operation. But subtraction of two pointers is allowed since this will give you the number of elements lying between the two addresses.
2
2
subtraction of two same type of pointers is allowed in case of array or string and the result gives the no of elements between them.
0
0

Related questions