473,497 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

typecasting using pointer

13 New Member
int *p, *q;
p= (int *) 60;
q= (int *) 20;
printf("%d", p-q);


the answer is 10

m lil unsure about wat does (int *) 60 means

if is it memory location numbered 60,as it seems...then it is possible that this memory area is not available so output should be undefined.

need help with this conceptual doubt
Jul 24 '10 #1
1 1196
donbock
2,426 Recognized Expert Top Contributor
The expression p-q involves pointer arithmetic. This pointer expression is only legal if p and q point to the same type, if p and q both point to actual variables of that type, and if p is greater than q. If those constraints are met, then the expression computes the number of variables of that type that fit in the memory region that starts at q and ends at p.

The answer you got implies that sizeof(int) is 4.
Jul 24 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
8442
by: venkatesh | last post by:
Hi Members, I need to convert Char Pointer to a Structure.How Can i typecast this. thanks in advance venkat
3
1534
by: Makiyo | last post by:
how do u do something like this char x; x = "hello"; I got an error, but is there a way I can do it without using pointer? thx ; )
9
10675
by: dati_remo | last post by:
Hi, is it possible to find the dimension of an array using a pointer? main() { int a; f(a); return; }
3
2690
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h>...
31
2205
by: arun | last post by:
suppose i have a pointer to an array of integers.can i initialize each member of the array using pointers?plz explain
16
10342
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what...
7
1947
by: nabeel.girgis | last post by:
I am passing a vector by reference into a function and I am trying to use a pointer in that function. I get an error saying : '=' : cannot convert from 'std::vector<_Ty> *' to 'int *' when I...
5
11209
by: WittyGuy | last post by:
How to typecast a "function pointer" to "const void*" type in C++ way? int MyFunction (double money); // Function prototype const void* arg = (const void*)MyFunction; // type casting...
29
3619
by: shuisheng | last post by:
Dear All, The problem of choosing pointer or reference is always confusing me. Would you please give me some suggestion on it. I appreciate your kind help. For example, I'd like to convert a...
1
2302
by: geervani | last post by:
hello, Can anybody just tell me how to scan or input a 2d array using pointer i e indirect reference. I am allocating memory the array dynamically. the statement i am using is int *a;...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.