[algogeeks] Re: C output 2

2011-07-27 Thread private.joker
Passing a pointer across functions does not create any problem and doesn't cause memory leak. but passing an array ,for eg int *fun() { int a[12]; return a; } this creates memory leak as the call stack no more holds the array. So, in essence, though int *a and int a[] behave quite similarly on

Re: [algogeeks] C ouput

2011-07-25 Thread private.joker
I guess I got that. (&a + 1) increments the pointer to the array(&a here) according to the size of array where as p, being a pointer to an int gets incremented by the size of int(4 byte in 32 bit compiler) with the statement p = p+1 Correct me if i am wrong. -- You received this message becaus

Re: [algogeeks] C ouput

2011-07-25 Thread private.joker
#include int main() { int a[5] = {1,2,3,4,5}; int *p = &a; p=p+1;; printf("%d",*(p)); getch(); return 0; } After p=p+1, p should point to the next byte after 5, but output in this case 2. That is p is just travelling inside the array. Is thr any diff b/w incrementing whi