can anyone please tell me whats actually happening in this code.
Seems to be as if incremented pointer is pointing to the next bit of same int.
Answer is 2,0
Thanks in advance

#include<stdio.h>
#include<conio.h>

void main()
{
  int arr[3]={2,3,4};
  char *p;
  p=arr;
  p(char*)((int *)(p));
  printf("%d",*p);
  p=(int*)(p+1);
  printf("%d",*p);

 getch();
}

What the ..? I mean, How the ...?

can anyone please tell me whats actually happening in this code.
Seems to be as if incremented pointer is pointing to the next bit of same int.

Why don't you try it in your compiler.did you?

Answer is 2,0

So you did try it and it actually compiled and ran?

What the ..? I mean, How the ...?
Why don't you try it in your compiler.did you?So you did try it and it actually compiled and ran?

Its a Question from "test Your C Skills" Book . I ran it and it showed the very same result as was printed in the book.

But I am not able to find the logic.

can u plz explain how the processing is going on ?????????

I ran it and it showed the very same result as was printed in the book.

Which compiler are you using?

But I am not able to find the logic.

me too.

can anyone please tell me whats actually happening in this code.

I'd have trouble writing worse code intentionally. If you got that code from a book, my recommendation is to burn the book so as to protect other hapless beginners from reading it. The author is clearly incompetent.

I ran it and it showed the very same result as was printed in the book.

I ran it--against my better judgment--and it resulted in my desktop process crashing and being forcefully restarted. That's consistent with a quick glance at the code which shows it to exhibit undefined behavior.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.