COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### pointers #6

• Email
• Follow

```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

See related articles to this posting

```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.....

#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
57 Views

Similar Articles

12/9/2013 8:10:18 AM
[PageSpeed]

Similar Artilces:

Passing pointers
Hi, I have loaded an ActiveX component into Matlab using: h= actxserver('prjMyProj.MyProj'); I can see the signatures for one method e.g.: [int32, SafeArray Pointer(single), SafeArray Pointer(single)] CaptMem(handle, int32, SafeArray Pointer(single), SafeArray Pointer(single)) My problem is this. How do I invoke this method in Matlab? Any help greatfully appreciated, Jeff

Pointers again: Seg Fault.
Hi All, After having posted my queries on memory allocation in a previous thread, I find that my program is indeed doing segmentation fault. Now I have zeroed in exactly the method of a class which is producing seg fault that it should not be producing. So this has brought me to a set of some more interesting questions: 1. What is the difference between A *ptrA and A *&ptrA ? Passing by reference makes sense while passing objects, but passing pointers in this format.... 2. The problem that I have is: suppose I have a class A and its method MA1 double A::MA1(B *arg1, C *arg2, D *arg3... related content]..... I guess you should be passing the pointers by reference, since you want any change to them to be reflected back to the caller. So, something like this: void method (type*& tptr) { tptr = new type; type *ptr = new type; *tptr = *ptr; //Don't forget to delete ptr. delete ptr; } That should do it. Now, if the caller passes an uninitialized pointer, (which I believe it shouldn't), then it will be perceived as changed to the caller. Something like: void foo (void) { type *ptr; method (ptr); //Whowa, after return, ptr is initialized. //Now, who will delete ptr

Domain Pointers
Hello Friends, Need some help on domain pointers over subdomain. My requirement is that we have couple of subdomain like Example1.com Should point to ex1.example.com Example2.com Should point to ex2.example.com This is what my requirement is , just wanted to know how can i Achieve this and do i need to configure my .htaccess file? New to domain pointing world. Thanks Abhis andy wrote: > Hello Friends, > Need some help on domain pointers over subdomain. My requirement is > that we have couple of subdomain like > > Example1.com Should point to ex1.example.com > >...; Hello Friends, > Need some help on domain pointers over subdomain. My requirement is > that we have couple of subdomain like > > Example1.com Should point to ex1.example.com > > Example2.com Should point to ex2.example.com > > This is what my requirement is , just wanted to know how can i Achieve > this and do i need to configure my .htaccess file? > > New to domain pointing world. Not a sendmail question.

Procmail pointers #53
Archive-name: mail/procmail/pointers Posting-Frequency: 2 times a month Maintainer: Jari Aalto <jari.aalto@poboxes.com> Announcement: "Procmail resources" Last updated: 1999-04-21 v1.72 pm-tips.txt Faq archive is at http://www.faqs.org/faqs/ The following list below is an excerpt from a bigger document. http://www.procmail.org/jari/pm-tips.html My Procmail module library page is at http://www.procmail.org/jari/pm-tips.html Era's exellent procmail link page (including procmail FAQ) is at http://www.iki.fi/~era/procmail/links.html 4.0 Procmail pointers 4.1 Where to get procmail binary ftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/ 4.2 Where is procmail developed Philip Guenther <guenther@gac.edu> is currently taking care of and coordinating procmail bug fixes. Please send any procmail bugs to the mailing list or to <bug@procmail.org>. The development mailing list is running SmarList at <procmail-dev@procmail.org>. Furher patch and bug info can be found at: http

Linking an array of const pointers
I have an array (much messier than this cut-down example) that I want to hive off into another source file, but the two compiled files won't link: m.cc: extern int *const table[]; int main() { return *table[0]; } t.cc: static int t1[] = { 1, 2, 3 }; static int t2[] = { 2, 3, 4 }; int *const table[] = { t1, t2 }; g++ says: \$ g++ -std=c++98 -pedantic m.cc t.cc /tmp/ccniFOW7.o: In function `main': m.cc:(.text+0x7): undefined reference to `ns::table' collect2: ld returned 1 exit status It works as one file where the content of t.cc follows mai

Array of function pointers
? Not really, but it doesn't harm either. > I could not understand why there is no error due to '*' at line no. 20. > Could anybody help me ? Let's have void f(void) {} void (*pf)(void) = &f; /* ...= f goes as well. */ We get: &f -> pointer to function f -> function pf -> pointer to function *pf -> function Now, like arrays, functions usually decay to pointers to them: (&f)() -> (pointer to function)() (f)() -> (function)() -> (pointer to function)() (pf)() -> (pointer to function...)) -> *(function) -> *(pointer to function) -> function etc. So you can pretty much replace any function() with a (******function)() and it's the same thing. The array you have is just an extra layer of complexity. On Thu, 4 Dec 2003, Jarno A Wuolijoki wrote: > Now, like arrays, functions usually decay to pointers to them: Oh, let's fix an "implied" thinko before anyone else catches: Arrays will of course decay to pointers to their elements, not to pointers to itself.

Need more help with pointers ...
Hi, I'm back with more pointer questions and looking for a good sample. Basically trying to write an RPG sample to match a Cobol sample ... basically an api calls a dll (service program) with a control block containing pointers and expects an answer returned via the pointer. Our Cobol service program sample (which is working just fine) has a linkage section control block that looks like ... 037600 01 PGM-DATA. 037700 05 CPG. 037800 10 DATA-LENGTH PIC S9(4) BINARY. 037900 10 FILLER PIC X(2). 038000 10 FLAG-VALUE... on the next line for alignment. 040900 10 FILLER PIC X(12). 041300 10 INSTRING PIC X(80). There are also 01 statements for MESSAGEAREA and ANSWERAREA strings and eventually there is a ... SET MESSAGE_ADDRESS TO ADDRESS OF MESSAGEAREA SET ANSWER_ADDRESS TO ADDRESS OF ANSWERAREA The pointers are initialized by the program that calls the service program and depending on value of INSTRING there are lengths returned in the lengths and data returned into the pointers. So I started by checking the net for RPG pointer samples, I found subject very

DECNet over IP pointers
I'm having a little DECNet over IP issue that has me baffled. Given four machines (all with DECnet Plus) at two sites , connected by VPN: SUBNET 192.168.1.0/24 Node1: DECnet 1.3 - IP ...3 Node2: Decnet 1.5 - IP ...5 SUBNET 192.168.2.0/24 NodeA: DECnet 1.2 - IP ...2 NodeB: DECnet 1.4 - IP ...4 Node2 is fairly new. Appropriate users are proxied across nodes as desired. think I broke the configuration on NodeA when I was trying to remember how to set it up to work over IP. Name service is just (Local, Registry). Right now, everything works, except NodeA, which used to work and now

Using pointers in fortran 95
Hello everybody, I am having troubles understanding if the way I am using pointers in the module Module_Neighbors is conform to f95 standard or not. I had problems with this on the pgi compiler (version 5.2-4 and 6.0), which in some partcular case returns a ierr /= 0 for the first deallocate statement in the subroutine "Delete". Can anybody help? I enclose an example of the way I am using the module in my code. Thank you beforehand Massimo ======================================================================== MODULE Module_Neighbors IMPLICIT none TYPE Neighbors INTEGER :: no=0 INTEGER, DIMENSION (:), POINTER :: nb=>null() END TYPE Neighbors CONTAINS SUBROUTINE Start(neigh,nmol) IMPLICIT none TYPE(Neighbors), DIMENSION (:), POINTER :: neigh INTEGER :: nmol INTEGER :: i ALLOCATE(neigh(nmol)) DO i=1,nmol neigh(i) % no = 0 NULLIFY(neigh(i) % nb) END DO END SUBROUTINE Start SUBROUTINE Delete(neigh) IMPLICIT none INTEGER :: i,ierr TYPE(Neighbors), DIMENSION (:), POINTER :: neigh IF(ASSOCIATED(neigh)) THEN DO i=1,SIZE(neigh) IF(ASSOCIATED(neigh(i) % nb

Procmail pointers #47
Archive-name: mail/procmail/pointers Posting-Frequency: 2 times a month Maintainer: Jari Aalto <jari.aalto@poboxes.com> Announcement: "Procmail resources" Last updated: 1999-04-21 v1.72 pm-tips.txt Faq archive is at http://www.faqs.org/faqs/ The following list below is an excerpt from a bigger document. http://www.procmail.org/jari/pm-tips.html My Procmail module library page is at http://www.procmail.org/jari/pm-tips.html Era's exellent procmail link page (including procmail FAQ) is at http://www.iki.fi/~era/procmail/links.html 4.0 Procmail pointers 4.1 Where to get procmail binary ftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/ 4.2 Where is procmail developed Philip Guenther <guenther@gac.edu> is currently taking care of and coordinating procmail bug fixes. Please send any procmail bugs to the mailing list or to <bug@procmail.org>. The development mailing list is running SmarList at <procmail-dev@procmail.org>. Furher patch and bug info can be found at: http