Shaily Shah
What is output of following program and why??


main() {
char *p;
int *q;
long *r;
p=r=q=0;
p++;
q++;
r++;
printf("%p %p %p",p,q,r); }
Like · Comment ·
Mosam Patel and Darshan Desai like this

Rohan Pradhan

ans is 111bcoz every thing has some ranges frm negative to positive ,,so 0,wud b in alll nd also ,wud increase it by 1,so....
Like ·

Vikas Jivani

ans is 111
Like ·

Shaily Shah

No..answer is 0001 0002 0004.... but dont know how??
Like ·

Darshan Desai

my answer is 111 because increment ( ) give you
Like ·

Darshan Desai

sorry my mistake because you give pointer variable so please see pointer programme
Like ·

Mosam Patel

plz dont ask about any c programe its so boring. Java .Net is awsm.
Like ·

Bhuro Patel

@Mosam Patel: If you learn C/C++ thoroughly you can learn any programming language. .Net and Java does not require much programming as there are lots of readymade methods are available, henece only brilliant people can C/C++.
Like ·

Bhuro Patel

@Shaily Shah: The answer 0001 0002 0004 is correct. First and most important thing is "%p" will print memory address, not value pointed by pointer. So whatever output printed on screen (on screen , here 0001, 0002, 0004) are memory address. Now you initialised all pointers to memory location 0x0000 (at line p=r=q=0. After that you incremented each ponter one time. So after incrementing each pointer, ponter p will contain memory address 0x0001 (as char is of 1 byte), pointer q will contain memory address 0x0002 (as int is of 2 byte) and ponter r will contain memory address 0x0004 (as long is of 4 byte). Hence you are getting answer 0001 0002 0004. Got it.
Like ·
Download Android App