Hi everyone!..
I'm back and sorry for these idotic questions.
I need help on understanding the following program. When I run it I
got the answer 2 5, but I can't understand how it is happenning. Can
anybody help me on this.....
#include<stdio.h>
int main()
{
int a[][3] = { 1,2,3 ,4,5,6};
int (*ptr)[3] =a;
printf("%d %d " ,(*ptr)[1], (*ptr)[2] );
++ptr;
printf("%d %d" ,(*ptr)[1], (*ptr)[2] );
return(0);
}
|
|
0
|
|
|
|
Reply
|
chuthurika (5)
|
2/11/2005 5:37:45 PM |
|
Chathu wrote on 11/02/05 :
> Hi everyone!..
> I'm back and sorry for these idotic questions.
> I need help on understanding the following program. When I run it I
> got the answer 2 5, but I can't understand how it is happenning. Can
> anybody help me on this.....
Comments added:
#include<stdlib.h>
#include<stdio.h>
int main (void)
{
/* Define an array of 2 arrays of 3 int's */
int a[][3] =
{
{1, 2, 3},
{4, 5, 6}
};
/* Define a pointer to an array of 3 int's
Initialize it with the address of the previous array
Actually, points to its first array of 3 int's.
*/
int (*ptr)[3] = a;
/* display the elements [1] and [2] of the first array */
printf ("%d %d\n", (*ptr)[1], (*ptr)[2]);
/* increment the pointer value. Due tu pointer arithmetics,
* points to the second array
*/
++ptr;
/* display the elements [1] and [2] of the second array */
printf ("%d %d\n", (*ptr)[1], (*ptr)[2]);
/* Dev-C++ trick (ignore it) */
system ("pause");
return 0;
}
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"Mal nommer les choses c'est ajouter du malheur au
monde." -- Albert Camus.
|
|
0
|
|
|
|
Reply
|
emdel (952)
|
2/12/2005 8:41:02 AM
|
|
|
1 Replies
37 Views
(page loaded in 0.072 seconds)
Similiar Articles: Passing pointer between different mex functions - comp.soft-sys ...Hello, I'm trying to pass a pointer between two different mex functions. To give you a big picture, here is what I'm trying to achieve in general: ... procedure() pointer - comp.lang.fortranHi, i am trying to do the following, with no success whatsoever: create a type (myType), that has a procedure() pointer. Then this pointer must po... How to find lost pointers to memory blocks - comp.soft-sys.matlab ...Hi All, How can I retrieve lost pointers to memory blocks. E.g. when my application crashes, I lose my pointers to the memory blocks, which results... Todays panic: BAD TRAP: type=31 rp=2a10056b110 addr=8 mmu_fsr=0 ...Todays panic: BAD TRAP: type=31 rp=2a10056b110 addr=8 mmu_fsr=0 occurred in module "ufs" due to a NULL pointer dereference Follow How Do I Add a pointer or arrow to a picture ? - comp.graphics ...Hi all I have a picture of a car engine and I want to highlight a certain engine part by adding an arrow or pointer by the side of it to make it inst... Put with @ column pointer - comp.soft-sys.sas@6 ageyrs z5.2 @11 htcm z7.3; run; And here is the output I am getting ... use column and line pointer controls to position the output pointer. To move the pointer ... Howto migrate SVM FS bet server - comp.unix.solaris> > Thanks in advance for any pointers. I'd use ufsdump/ufsrestore if you have screwy files. cp seems to not handle stuff like that gracefully. Controlling mouse pointer using hand movement - comp.soft-sys ...I need to develop a project in which i need to control movement of the mouse pointer on my screen by moving my hand in front of a web camera.i can tra... Pointer Justification - comp.dcom.sdh-sonetDear Sir, [TM1][ADM][TM] If the clock of Terminal Mux [TM1] is f1 & the clock of [ADM] is f2 (f1>f2), then whether ADM will do +ve pointer just... External variables - comp.lang.asm.x86But, while the case in section 6.1 of the FAQ is very obvious and easily understood, since arrays are not pointers (yes I know that), and I could never did that mistake ... Six-pointer - Wikipedia, the free encyclopedia"Six-pointer" is a sporting cliché, particularly used in association football, used to describe a game between two teams with similar league positions, in leagues ... Codet "8 Pointers" 6 Pocket Wool Pants - Acadiana OutfittersWork Pants & Shorts ... • 24 oz. 75% recycled wool, 20% nylon and 5% other fibers. • 2 front pockets. • 2 rear “reece” pockets with button flaps. C++ Tutorial #6, Pointers (1) - YouTubeUploaded by zaychenok on Dec 29, 2007 Pointers, an Introduction Category: Howto & Style Tags: technology computer science programming video tutorials ... Amazon.com: High Quality Green Laser Pointer 6 in 1 (With 5 ...Wave length: 532nm. Range in darkness: more than 1000 meters. Power supply:AAA Batteries x2 (included) Laser color: Green Working Curreent:60mA ; Working Voltage:3-3 ... Amazon.com: 6-Pack of 3-IN-1 Strong Red Presentation Key Chain ...This is a pack of 6 / 3-IN-1 / key chain laser pointers! Each laser has a red pointer, white light and black light! Lasers come in 6 assorted colors - Colors per pack ... 6/23/2012 1:01:43 AM
|