#includestdio.h
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
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 because
On 7/25/11, private.joker abhi123khat...@gmail.com wrote:
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
@ambika
20 questions of MCQ with negative marking
mostly C/DS
then 1-2 que of OS
then puzzle and apti
2 questions of programming
longest increasing subarray and spiral matrix printing
On Sat, Jul 23, 2011 at 8:30 PM, Akshata Sharma
akshatasharm...@gmail.comwrote:
Thanks all :) its clear now..
@sagar : thnx !!!
On Sun, Jul 24, 2011 at 1:44 PM, sagar pareek sagarpar...@gmail.com wrote:
@ambika
20 questions of MCQ with negative marking
mostly C/DS
then 1-2 que of OS
then puzzle and apti
2 questions of programming
longest increasing subarray and spiral matrix printing
On Sat,
main()
{
int a[5] = {1,2,3,4,5};
int *ptr = (int*)(a+1);
printf(%d %d , *(a+1), *(ptr-1) );
}
output: 2 5
can someone please exlplain how we are getting 5?
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send
a denotes the address of array
a+1 increments a by size of array and stores in ptr.i.e. ptr points to
end of array
hence ptr-1 will print 5
--
Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
On Sat, Jul 23, 2011 at 6:03 PM, Akshata Sharma
that question was just asked by amazon in mnnit :)
On Sat, Jul 23, 2011 at 6:10 PM, Amol Sharma amolsharm...@gmail.com wrote:
a denotes the address of array
a+1 increments a by size of array and stores in ptr.i.e. ptr points
to end of array
hence ptr-1 will print 5
--
Amol Sharma
Amazon ..!! :)
a increments by whole array not just an int value..!!
u marked 2 1 ??
On Sat, Jul 23, 2011 at 6:03 PM, Akshata Sharma
akshatasharm...@gmail.comwrote:
main()
{
int a[5] = {1,2,3,4,5};
int *ptr = (int*)(a+1);
printf(%d %d , *(a+1), *(ptr-1) );
}
output: 2 5
can
same here in IIIT !! :P
On Sat, Jul 23, 2011 at 6:15 PM, sagar pareek sagarpar...@gmail.com wrote:
that question was just asked by amazon in mnnit :)
On Sat, Jul 23, 2011 at 6:10 PM, Amol Sharma amolsharm...@gmail.comwrote:
a denotes the address of array
a+1 increments a by size of
@Akshata:
Whenever you increase any variable then it increases according to its type.
Here the address of array 'a' is being increased.( a+1 ).
so the address of 'a' will temporarily increased to 20 bytes and then that
is assigned to ptr.
so ptr is now pointing to any value in the memory just
same question in MS written :P
On Sat, Jul 23, 2011 at 5:49 AM, Manish Kumar manish.monu...@gmail.com wrote:
@Akshata:
Whenever you increase any variable then it increases according to its type.
Here the address of array 'a' is being increased.( a+1 ).
so the address of 'a' will temporarily
@sagar : what was the question paper pattern for amazon
On Sat, Jul 23, 2011 at 6:32 PM, radha krishnan
radhakrishnance...@gmail.com wrote:
same question in MS written :P
On Sat, Jul 23, 2011 at 5:49 AM, Manish Kumar manish.monu...@gmail.com
wrote:
@Akshata:
Whenever you increase
Thanks all :) its clear now..
On Sat, Jul 23, 2011 at 6:37 PM, ambika iyer balu200...@gmail.com wrote:
@sagar : what was the question paper pattern for amazon
On Sat, Jul 23, 2011 at 6:32 PM, radha krishnan
radhakrishnance...@gmail.com wrote:
same question in MS written :P
On Sat,
14 matches
Mail list logo