f



pointer to pointer

Its just a very simple and basic program to learn exactly what is 
described in comments here. Can you provide a better (and short) 
exercise ?


/* A program to learn how to use a pointer to a pointer. Here we take an 
array of char pointers. A char* in the array, of course, points
 * to some char. Array has only one element. We change the value of char 
pointed by array's element using a function.
 *
 * VERSION 0.0
 */
#include <stdio.h>

void replace_char_value(char* [], char);

int main(void)
{
  char* arrc[2] = {0};
  char c = 'c';
  arrc[0] = &c;

  printf("*arrc: %p, **arrc: %c\n", (void*)*arrc, **arrc); 
  replace_char_value(arrc, 'w');
  printf("*arrc: %p, **arrc: %c\n", (void*)*arrc, **arrc); 

  return 0;
}


void replace_char_value(char* arr[], const char t)
{
  **arr = t;
}

==================== OUTPUT =======================
[arnuld@dune programs]$ gcc -ansi -pedantic -Wall -Wextra pointer-to-
pointer.c
[arnuld@dune programs]$ ./a.out 
*arrc: 0xbfffe8ab, **arrc: c
*arrc: 0xbfffe8ab, **arrc: w
[arnuld@dune programs]$ 




-- 
http://www.lispmachine.wordpress.com
0
arnuld
12/22/2010 3:43:25 AM
comp.lang.c 30656 articles. 5 followers. spinoza1111 (3246) is leader. Post Follow

7 Replies
1145 Views

Similar Articles

[PageSpeed] 39

On 12/22/10 04:43 PM, arnuld wrote:
> Its just a very simple and basic program to learn exactly what is
> described in comments here. Can you provide a better (and short)
> exercise ?

Parse the arguments to a program.  Don't forget argv is a pointer to 
pointer!

Given ./a.out -a 10 -b 20

print out the values of a and b.

-- 
Ian Collins
0
Ian
12/22/2010 4:05:29 AM
arnuld <sunrise@invalid.address> writes:

> Its just a very simple and basic program to learn exactly what is 
> described in comments here. Can you provide a better (and short) 
> exercise ?

Several linked-list idioms involve a pointer-to-a-pointer.  The most
obvious ones are

  * Removing an item from a singly-linked list.

  * Inserting an item into a sorted singly-linked list.

  * Building up a list in order, one at a time.

The last is especially simple, and will serve as an example of the
general technique.  Suppose that you have a node structure like this

        struct node {
          struct node *next;
          /* other members here */
        };

You build a list in order by remembering where the trailing link is.
Initially, the trailing link is actually the list head pointer.

        struct node *head, **tail = &head;
        struct node *n;

To attach a new node n to the list, you do this:

        *tail = n;
        tail = &n->next;

and finally you terminate the list like this:

        *tail = 0;

I encourage you to draw diagrams to see why this works.

Of course, you can abstract the core of the algorithm into a function.
If you do this in the obvious way, you will find that you need to pass
in the /address/ of the trailing-link pointer, which is a pointer to a
pointer to a pointer:

        static link_to_end(struct node *n, struct node ***tail)
        {
          **tail = n;
          *tail = &n->node;
        }

This is the simplest natural example I know of for a `three-star'
pointer.

-- [mdw]
0
mdw
12/22/2010 12:10:36 PM
> On Wed, 22 Dec 2010 17:05:29 +1300, Ian Collins wrote:

> Parse the arguments to a program.  Don't forget argv is a pointer to
> pointer!
> 
> Given ./a.out -a 10 -b 20
> 
> print out the values of a and b.


How about this. Two questions:

 (1) How to write it better ?
 (2) How to avoid OUTPUT-2 ?



/* A program given by Ian Collins on CLC. Parse input to C Program this 
way:
 * GIVEN: ./a.out a -10 b 2, print out values of a and b
 *
 * Assumptions: separator between 2 values is one space. User may enter 
two elements together without any value but then program will
 *              take 2nd element as value of first element.  
 * VERSION 0.0
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void printElementAndValue(char** t);

int main(int argc, char* argv[])
{
  /*  char* pe;  Pointer to element */
  /*  char* pv;  Pointer to value */
  char** t;

  if(1 == argc)
    {
      printf("USE: ./a.out [ELEMENT1] [VALUE1] [ELEMENT2] [VALUE2] ....
\n");
      exit(EXIT_FAILURE);
    }
  else if(0 == (argc % 2))
    {
      printf("Please enter proper input: [ELEMENT] [VALUE] \n");
      exit(EXIT_FAILURE);
    }
  
  for(t = argv + 1; *t; ++t, ++t) 
    {
      printElementAndValue(t);
    }

  return 0;
}


void printElementAndValue(char** t)
{
  const char element_identifier = '-';
  if(strchr(*t, element_identifier))
    {
      printf("%s = ", *t++);
      printf("%s\n", *t);
    }
  else
    {
      printf("Improper input. Key identifier, '-', was not used ?\n");
    }
     
}
==================== OUTPUT ==============================
[arnuld@dune programs]$ gcc -ansi -pedantic -Wall -Wextra PtoP_argv-
parse.c
[arnuld@dune programs]$ ./a.out -a 10 -b 3
-a = 10
-b = 3
[arnuld@dune programs]$ 



================= OUTPUT-2 ==========================
[arnuld@dune programs]$ ./a.out -a 10 -b *
-a = 10
-b = a.out
Improper input. Key identifier, '-', was not used ?
Improper input. Key identifier, '-', was not used ?
problem-scanf.c = PtoP_argv-parse.c
PtoP_argv-parse.c~ = scanf-problems.c
sequence-point.c = strcpy.c
Improper input. Key identifier, '-', was not used ?
[arnuld@dune programs]$ 




-- 
http://www.lispmachine.wordpress.com
0
arnuld
12/23/2010 7:29:45 AM
On Dec 21, 8:05=A0pm, Ian Collins <ian-n...@hotmail.com> wrote:
> On 12/22/10 04:43 PM, arnuld wrote:
>
> > Its just a very simple and basic program to learn exactly what is
> > described in comments here. Can you provide a better (and short)
> > exercise ?
>
> Parse the arguments to a program. =A0Don't forget argv is a pointer to
> pointer!
>
> Given ./a.out -a 10 -b 20
>
> print out the values of a and b.
>

I don't get the point of this exercise. Maybe I'm missing "it'.
Anyways, here is what I came up with..

#include <stdio.h>

int main(int argc, char **argv)
{
  int i;
  char dash, letter;

  for (i =3D 1; i < argc; i++) {
    dash =3D argv[i][0];
    letter =3D argv[i][1];

    if (dash  =3D=3D '-' && letter =3D=3D 'a') {
      printf("a =3D %s\n", argv[++i]);
    }
    if (dash  =3D=3D '-' && letter =3D=3D 'b') {
      printf("b =3D %s\n", argv[++i]);
    }
  }

  return 0;
}

[cdalten@localhost oakland]$ gcc -Wall -Wextra -ansi -pedantic
parseab.c -o parseab
[cdalten@localhost oakland]$ ./parseab -a 10 -b 20
a =3D 10
b =3D 20
[cdalten@localhost oakland]$ ./parseab -a 10
a =3D 10
[cdalten@localhost oakland]$ ./parseab -b 40
b =3D 40
[cdalten@localhost oakland]$ ./parseab
[cdalten@localhost oakland]$ ./parseab b 40
[cdalten@localhost oakland]$ ./parseab a 40
[cdalten@localhost oakland]$ ./parseab a 40 b 40
[cdalten@localhost oakland]$ ./parseab -b 40 -a 100
b =3D 40
a =3D 100
[cdalten@localhost oakland]$


0
Chad
12/25/2010 8:23:10 PM
On Dec 25, 12:23=A0pm, Chad <cdal...@gmail.com> wrote:
> On Dec 21, 8:05=A0pm, Ian Collins <ian-n...@hotmail.com> wrote:
>
> > On 12/22/10 04:43 PM, arnuld wrote:
>
> > > Its just a very simple and basic program to learn exactly what is
> > > described in comments here. Can you provide a better (and short)
> > > exercise ?
>
> > Parse the arguments to a program. =A0Don't forget argv is a pointer to
> > pointer!
>
> > Given ./a.out -a 10 -b 20
>
> > print out the values of a and b.
>
> I don't get the point of this exercise. Maybe I'm missing "it'.
> Anyways, here is what I came up with..
>

And here is my attempt at the pointer solution. It's kind of ugly, but
it appears to work correctly...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
  char *letter =3D"";
  char *number =3D"";

  while (--argc > 0) {
    letter =3D *++argv;
    number =3D *++argv;

    if (letter !=3D NULL && (strcmp(letter, "-a")) =3D=3D 0 ) {
      if(number !=3D NULL && (strcmp(number, "-b")) =3D=3D 0 ) {
        number =3D *++argv;
        if (number !=3D NULL) {
          printf("No number provided for a\n");
          printf("b =3D %s\n", number);
          exit(EXIT_SUCCESS);
        } else {
          printf("No number provided for a and b\n");
          exit(EXIT_FAILURE);
        }
      }
      printf("a =3D %s\n", number ? number : "No number provided for a
\n");
    }
    if (letter !=3D NULL && (strcmp(letter, "-b")) =3D=3D 0 ) {
      if(number !=3D NULL && (strcmp(number, "-a")) =3D=3D 0 ) {
        printf("No number provided for b and a\n");
        exit(EXIT_FAILURE);
      }
      printf("b =3D %s\n", number ? number : "No number provided for b
\n");
    }
  }

  exit(EXIT_SUCCESS);
}
[cdalten@localhost oakland]$ gcc -g -Wall -Wextra -ansi -pedantic
parseab2.c -o parseab2
[cdalten@localhost oakland]$ ./parseab2
[cdalten@localhost oakland]$ ./parseab2 -a
a =3D No number provided for a

[cdalten@localhost oakland]$ ./parseab2 -a -b
No number provided for a and b
[cdalten@localhost oakland]$ ./parseab2 -a -b 10
No number provided for a
b =3D 10
[cdalten@localhost oakland]$ ./parseab2 -a 10 -b
a =3D 10
b =3D No number provided for b

[cdalten@localhost oakland]$ ./parseab2 -a 10 -b 20
a =3D 10
b =3D 20
[cdalten@localhost oakland]$ ./parseab2 -b 10 -a
b =3D 10
a =3D No number provided for a

[cdalten@localhost oakland]$ ./parseab2 -b 10 -a 50 20
b =3D 10
a =3D 50
[cdalten@localhost oakland]$
0
Chad
12/25/2010 9:57:24 PM
On 2010-12-25, Chad <cdalten@gmail.com> wrote:
> #include <stdio.h>
> #include <string.h>
> #include <stdlib.h>
>
> int main(int argc, char **argv)
> {
>   char *letter ="";
>   char *number ="";
>
>   while (--argc > 0) {
>     letter = *++argv;
>     number = *++argv;

You iterate argc-1 times through this loop, and in each iteration
argv is advanced at least two times. That means that for certain
argument lists you're accessing non-existing elements of argv.

Let's take, for example, the argument list ``the quick brown fox''.
argc=5, argv[0]=progname, argv[1]="the", argv[2]="quick",
argv[3]="brown", argv[4]="fox", argv[5]=NULL.

In the first iteration, you handle argv[1] ("the") and argv[2] ("quick").
In the second iteration, you handle argv[3] ("brown") and argv[4] ("fox").
In the third iteration, you handle argv[5] (NULL) and argv[6] (and
here the program goes off the rails).
0
Ike
12/26/2010 12:44:58 PM
> On Dec 26, 1:23=A0am, Chad <cdal...@gmail.com> wrote:


> I don't get the point of this exercise. Maybe I'm missing "it'.
> Anyways, here is what I came up with..
>
> #include <stdio.h>
>
> int main(int argc, char **argv)
> {
> =A0 int i;
> =A0 char dash, letter;
>
> =A0 for (i =3D 1; i < argc; i++) {
> =A0 =A0 dash =3D argv[i][0];
> =A0 =A0 letter =3D argv[i][1];
>
> =A0 =A0 if (dash =A0=3D=3D '-' && letter =3D=3D 'a') {
> =A0 =A0 =A0 printf("a =3D %s\n", argv[++i]);
> =A0 =A0 }
> =A0 =A0 if (dash =A0=3D=3D '-' && letter =3D=3D 'b') {
> =A0 =A0 =A0 printf("b =3D %s\n", argv[++i]);
> =A0 =A0 }
> =A0 }
>
> =A0 return 0;
>
> }

> ...SNIP....


I think "Ian Collins" meant uknown number of arguments (rather than
two). Still even if he meant two arguments -a and -b, still your
program confuses a bit because at first it iterates for --argc times
but then at same time it it handles only two variables (which may or
may not not equal to --argc). I think if you want to deal with only 2
argiments then (i < 3) must be the conditional check.

Nice cleaner code with array indexing though :)
0
arnuld
12/27/2010 11:20:38 AM
Reply:

Similar Artilces:

pointers, pointers, pointers...
Hi There, I came up with following sample code to demonstrate my issue: #include <18F87K22.h> #device HIGH_INTS=TRUE, adc=16, ICD=TRUE #fuses NOWDT //No Watch Dog Timer #fuses WDT128 //Watch Dog Timer uses 1:128 #fuses HSM //Hi-Speed crystal oscillator #fuses NOBROWNOUT //No brownout reset #fuses NOPLLEN //No PLL enabled #fuses BBSIZ1K //1K words Boot Block size #fuses NOXINST //Extended set extension and Indexed typedef struct{ int8 foo, test; } TheStruct; TheStruct mystruct[5]; int16 myarr[2]; void Func(TheStruct *data, int16 *arr); void main (void) { myarr[0]=0xff; myarr[1]=0xaa; memset(&mystruct,0,sizeof(mystruct)); Func(myarr,&mystruct); while(true); } //------------------------------------------------------------------------------ void Func(TheStruct *strdat, int16 *arr) { strdat[0]->foo=(*arr[0]); strdat[0]->test=(*arr[1]); } This compiles just fine (CCS 4.119) but doesn't work, after the function, foo and test are still 0 cause myarr doesn't seem to be passed correctly to the function.... what am I doing wrong here? :( Thanks, Ron In <6549b0ed-900d-4279-b737-d8fa66831d94@r3g2000yqh.googlegroups.com> cerr <ron.eggler@gmail.com> writes: > TheStruct mystruct[5]; > int16 myarr[2]; > void Func(TheStruct *data, int16 *arr); > Func(myarr,&mystruct); Func is defined to...

c++: pointers to pointers
Hi, I have an array of pointers defined as such: myArray** ptr = new myArray[10]; for some reason i get a compile time error stating there is no default constructor for myArray. The problem is that i should not need to define one since myArray is a pointer to a pointer and so should not have a default constructor - its a primitive data type and not an object. Any help appreciated. Regards, A A wrote in news:3f9e5e27_1@news.iprimus.com.au: > Hi, > > I have an array of pointers defined as such: > > myArray** ptr = new myArray[10]; myArray** ptr = new myArray *[10]; &g...

Pointer-to-pointer-to-pointer question
The code example below shows the dynamic allocation of a 2D array. I must admit that it took quite a while for me to get there (I already have another posting to that effect), but I am glad that I finally got it working. Now here's the problem: I am able to get the 2D array dynamically allocated correctly as long as I am doing it "in-line" (i.e. without invoking any function). The moment I try to do it in another function, I get a core dump. Any help will be appreciated. Since this function is expected to update a pointer-to-pointer type, I am actually passing the pointer-to-pointer-to-pointer type to the function. What am I missing here? You can see that the source code works correctly when I am perform 2D array initialization "in-line" (i.e. by not invoking a function call) simply by un-commenting the line /* #define INLINE_INIT */ Masood /******************************************************/ #include <stdio.h> #include <stdlib.h> /*#define INLINE_INIT*/ #define MAXROWS 3 #define MAXCOLS 5 void buildTbl(int ***tblPtr, size_t numRows, size_t numCols) { *tblPtr = (int **)malloc(numRows*sizeof(int*)); /* C++ : *tblPtr = new (int*)[numRows]; */ for(size_t i = 0; i < numCols; i++) *tblPtr[i] = (int *)malloc(numCols*sizeof(int)); /* C++: *tblPtr[i] = new (int)[numCols]; */ } main() { int startVal = 5; int **tbl; #ifdef INLINE_INIT tbl = (int **)malloc(MAXROWS*sizeof(int*)); /* C++ : tbl = new (int*)[MAXROWS]; */ ...

pointer vs pointer to pointer
AIM: To write a queue with 3 operations. WHAT I GOT: It works PROBLEM: Have a question: Why do "pointer to pointer" in enqueue() and "a pointer" to deleteElement() both work fine ? Will enqueue() work fine if I pass just "a pointer" to it ? Will deleteElement() work fine if I pass "pointer to pointer" ? /* A queue implementataion with the operations that I need: * (1) Add element to the front of the queue * (2) remove an element with a unique ID (string constant) * (3) compare 2 elements (string comparison) * (4) print queue * ...

Pointer to Pointer or not?
Hi I am creating my own Queue class to learn about Queues and pointers. I have come across a question of two styles and I don't know if there are any dangers associated with them. I coded my remove function as follows template <class T> bool adsQ<T>::Remove(T* theData) { Qnode<T>* removeNode = 0; if (true == isEmpty()) { //cout << "False" << endl; return false; } else { /* What I am trying to achive here is to change the data pointed to by theData to the data pointed to by pData.*/ *theData =*(pHead->pData); //Data exchan...

Pointers for these pointers...?
Hi Everyone: I'm trying to develop a property list to include as metadata about my object classes. i.e. I want each class I'm developing to include a PropertyList which will contain ObjectProperty pointers. ObjectProperty is a class containing the typeid.name() of a type as it's ObjectType as well as an ObjectName and ObjectDescription. Basically 3 strings of metadata describing each of a class' member variables (and hopefully functions) so that the class can report to a query from another class what properties it has available for access at run time. Here is what I have and t...

pointer of pointer
Hi I have a structure, B_t is another structure typedef struct{ int len; unsigned char code[12]; B_t *b; }A_t Now I need to pass A_t into a function to evaluate I use pointer of pointer void evaluate(A_t **a) My question is how to evaluate the component of this structure (*a)->b??? seems not right Thanks a lot! <qianz99@gmail.com> wrote in message news:1178915812.306611.242380@y80g2000hsf.googlegroups.com... > Hi > > I have a structure, B_t is another structure > > typedef struct{ > int len; > unsigned char code[12]; > B_t *b; > }A_t > > Now I need to pass A_t into a function to evaluate > I use pointer of pointer > > void evaluate(A_t **a) > > My question is how to evaluate the component of this structure > > (*a)->b??? > > seems not right > It is right. It is ugly and so you might be better off with A_t *aptr; aptr = *a; aptr->b; Code that a machine can read correctly isn't necessarily easy for humans to read. The extra variable will almost certainly be optimised away by the compiler, so there is unlikely to be any efficiency penalty. -- Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm On May 11, 1:36 pm, qian...@gmail.com wrote: > My question is how to evaluate the component of this structure > > (*a)->b??? > It accesses member b of A_t, which a pointer to B_t. Whether it is right or not depends upon what you mean by 'eva...

pointers to pointers
Hi, i understood what pointers are and all stuff, and now i'm at the part with pointers to pointers and my book doesn't really help on this issue. let be: int a,*p,**q; how to make use of **q,*q and q ? Which who's address and/or who's value contains. I would like some examples like p=&a;// p contains the address of a and *p contains it's value but regarding **q,*q respectively q. Thanks. apropo wrote: > Hi, > i understood what pointers are and all stuff, and now i'm at the part > with pointers to pointers and my book doesn't really help on...

Pointers to pointers
How can you use a "pointer to a pointer" as a two dimensional array using 'new' and 'delete' rather than 'malloc' and 'free'? Thanks, Jonas Jonas Cord wrote: > How can you use a "pointer to a pointer" as a two dimensional array > using 'new' and 'delete' rather than 'malloc' and 'free'? Pretty much the same. int main() { int** data; data = new int*[100]; for (int i = 0; i < 100; ++i) data[i] = new int[100]; //use it for (int i = 0; i < 100; ++i) delete []...

pointer to a pointer
My situation: I have a function that takes a pointer to an FSref as an argument. In the body of the function is a function call that also takes a pointer to an FSRef. I need to pass my original FSRef, but since I have only a pointer to it, I am assuming I need to dereference it twice when I call the second function. However, using something like &&myFSRef in the second function doesn't work. Can anyone tell me the proper way to do this? Thanks. In article <1105802448.cd52b3255e6c95476ce23f7be215a6a3@teranews>, Steven Daedelus <sdaedelus@ira.gov> w...

Pointer to pointer Vs References to Pointer
Q . When to use use pointer-to-pointer and reference-to-pointer to modify a pointer passed to a function ? According to me Which is better : double pointers OR Reference to Pointer ? There is no clear advantage and depends on programmer =91s choice or habit . As Nilesh mentioned =94 Reference to pointer=94 makes code easy But Pointer to pointer makes code easy to understand. So one can use any one . Why Pointer to Pointer is generally used ? 1. Pointer to pointer can be used in C and C++ but reference to pointer is limited to C++. a. Generally people start learning programming from C . So they get used to pointer to pointer. b.Pointer to Pointer usage makes project porting in C or C++ easy. 2. Generally libraries uses pointer to pointer approach like COM uses pointer to pointer for CoCreateInstance or QueryInterface. Fourm : Could you please let me know if these are the only reasons or i am missing something? Thanks Vikrant Example #include "stdafx.h" void Ref2Poi(int * &p) { *p =3D 10; } void Poi2Poi( int ** p) { **p =3D 10; } int _tmain(int argc, _TCHAR* argv[]) { int i =3D 13; int j =3D 14; int *p =3D &i; int *q =3D &j; Ref2Poi(p); Poi2Poi(&q); return 0; } "bansalvikrant@gmail.com" <bansalvikrant@gmail.com> writes: > Q . When to use use pointer-to-pointer and reference-to-pointer to > modify a pointer passed to a function ? &g...

pointer c++//C#
Hi until recently I only knew some VB.NET and there were no pointers. Now I understand how to use them but still wonder why exactly they are needed? What do they look like in C#? Thanks and cheers Michael mikethebike wrote: > until recently I only knew some VB.NET and there were no pointers. Now > I understand how to use them but still wonder why exactly they are > needed? Uh... Because it would be harder without them, maybe? > What do they look like in C#? Ask in a C# newsgroup or get a book and look it up. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask mikethebike wrote: > Hi > until recently I only knew some VB.NET and there were no pointers. Now > I understand how to use them but still wonder why exactly they are > needed? > What do they look like in C#? > Thanks and cheers > Michael In C# everything is passed by reference by default. In C/C++ not. Take the following example (basic and maybe not accurate, but you'll get the point): typedef struct { double list[1000][1000]; } foo_t; void do_something(foo_t foo) { // Do something } int main() { foo_t foo; do_something(foo); } A copy of the original foo_t object will be created thus taking twice as much size in memory. By using a pointer or a reference it wouldn't. The other thing is that when using a pointer you can actually mo...

pointer-to-pointer to char
The following code can be compiled. But When I run it, it causes "Segmentation fault". int main(){ char **c1; *c1 = "HOW"; // LINE1 ++(*c1); *c1 = "ARE"; ++(*c1); *c1 = "YOU"; } c1 is a pointer-to-pointer to char. How to initialize c1 to three strings: "HOW", "ARE", "YOU"? Thanks a lot. Jack wrote: > The following code can be compiled. But When I run it, it causes > "Segmentation fault". > > int main(){ > char **c1; > > *c1 = "HOW"; // LINE1 > c1 doesn...

pointers and array of pointers
Hi, Like almost all of beginners I have problem understanding pointers. Please, look at this piece of code, and please explain me why myswap function doesn't work as it's supposed to do, whereas myswap2 is doing exactly what I want it to do - swaping pointers. Where I made a mistake? Thanks void myswap(char *pa, char *pb){ char *tmp; tmp=pa; pa=pb; pb=tmp; } void myswap2(char *sw[]){ char *tmp; tmp=sw[0]; sw[0]=sw[1]; sw[1]=tmp; } int main(void){ char *a="1111", *b="2222", *A[]={"1111","2222"}; printf("1: %s, 2: %s\n", a,...

pointers to pointers question
How come something like: #include <stdio.h> int main(int argc, char **argv) { char **arg; int i; for ( i = 0; argv[i] != NULL; ++i ) { puts(argv[i]); } for ( arg = argv; *arg != NULL; ++arg ) { puts(*arg); } return 0; } doesn't require a explicit & before argv in the for loop, but something like #include <stdio.h> #include <stdlib.h> int main(void) { char *ptr = "Garbage"; char **pptr; pptr = &ptr; printf("The value is: % s\n", *pptr); } does require an explict & Chad Chad w...

Pointer to Pointer to character
a simple program... #include <iostream> using namespace std; int main(int argc, char** argv) { cout<<argv<<endl; cout<<**argv<<endl; cout<<argv[0][0]<<endl; cout<<&argv[0]<<endl; cout<<&(argv[0][0])<<endl; // why not the same as &argv[0]? } why &argv[0] & &(argv[0][0]) difference? Howachen posted: > #include <iostream> You need to include "ostream" if you want to use "endl". > using namespace std; > > int main(int argc, char** argv) { > > ...

pointer to pointer question
struct pair_node { int i; double d; }; struct pair_node **x; The following is what I want to create. x -> [ ] -> (2,0.1) (3,0.2) (-1,?) [ ] -> (2,0.1) (3,0.3) (4,-1.2) (-1,?) [ ] -> (1,0.4) (-1,?) [ ] -> (2,0.1) (4,1.4) (5,0.5) (-1,?) [ ] -> (1,-0.1) (2,-0.2) (3,0.1) (4,1.1) (5,0.1) (-1,?) // Do I need an allocation before this loop for x? for(i = 0; i < N; ++i){ //dumps core on the following line, anyone can help me why? // am i missing something? nprob.x[i] = (struct pair_node *)malloc(sizeof(struct pair_node)*D); for(j = 0; j ...

Confused about pointer on pointer
Hi all, i've a problem with a simple example program: i've a variable: float *vertices; and want a function: initVertices(float **v, int l) which should init the vertices array. It should be filled with values from 0 to l (l should also have the size l) initVertices(float **v, int l){ // ? // ? } int main(int argc, char **argcv){ int l = 10; float *vertices=NULL; initVertices(&vertices, l); //should output 0.0, 1.0, 2.0, ... for(int i=0; i<l; i++) printf("%i, &quo...

Pointers to pointers #3
What do pointers to pointers accomplish? How does having a pointer to a pointer help a design or aglorithm? Where are they normally used? cman In article <1171819744.426037.176610@s48g2000cws.googlegroups.com>, cman <tilakb@gmail.com> wrote: >What do pointers to pointers accomplish? How does having a pointer to >a pointer help a design or aglorithm? Where are they normally used? > >cman > If you want to modify an object passed in the argument list of a function from within the function, you must pass a pointer to the object as the argument. So, if you want to mo...

Pointer to a Pointer to a struct
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void) { typedef struct { char **test; }Testing; Testing **p; p = malloc(sizeof(Testing)); p[0]->test[0] = malloc(sizeof(Testing)); strncpy(p[0]->test[0],"Hello World",20); printf("%s\n",p[0]->test[0]); return EXIT_SUCCESS; } Why does the following crash ? Not sure what i'm missing please advise thanks. -- Unix Systems Engineer The City of New York Dept. of Information Technology http://www.nyc.gov/doitt rbrown[(@)]doitt.nyc.gov http://www.rodrickb...

Why pointers to pointers used
I have used many OSS libraries which have a common structure like the following: They have init function which takes a pointer to pointer to the module data structure like this: module_init(struct module_ds ** p,.....); And usage example is like following: struct module_ds * p; p = NULL; module_init(&p,....); etc. Now i'm wondering why they do it this way? if i pass a plain pointer then it should be ok to declare a local pointer and allocate and initialize it. after initialization it can be returned by the fuction. but they always have a void type. Even if they remain "void&...

pointer to a pointer problems
An open book test I am taking, tasked me to write a function with the following prototype. Yea, its a test, so don't give me the implementation. But it is open book, so maybe I can at least get a few questions answered. // returns the next token in a string found seperated by the delimeter. upon return updates str to point to the next token in // the string after the one returned const char * nextToken(const char ** str, const char delimeter); When I look at this, it looks very c-style to me. I think it is unsafe. 1) I don't see a way to return a different string without allocating ...

using pointer to pointer(**)
Hello! I have noticed that if you want to return an object from a method the example I have seen always use **. Can somebody explain why? //Tony "Tony Johansson" <johansson.andersson@telia.com> kirjutas: > Hello! > > I have noticed that if you want to return an object from a method the > example > I have seen always use **. > > Can somebody explain why? > Seems like C code or unjustified premature optimization attempts. In C++ the simplest way to return an object from a function would be: class A {/*...*/}; A f() { return A(); } in...

Web resources about - pointer to pointer - comp.lang.c

Plaxton Pointer - Wikipedia, the free encyclopedia
The Plaxton Pointer (originally known as the Reeve Burgess Pointer , and later as the TransBus Pointer and Alexander Dennis Pointer ) is a successful ...

Michael Pointer (@michaelpointer) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Thread: I'm looking for pointers to a Google Maps API overview.
... outline for a map, making it super-easy to edit, and also to have it in the most convenient form for someone browsing over the data. Any pointers ...

Pointer for iPhone, iPad, and iPod touch on the iTunes App Store
Get Pointer on the App Store. See screenshots and ratings, and read customer reviews.

Kobe Bryant 45 Points (NBA Record 12 Three-Pointers) vs Seattle Super Sonics - Highlights 07/01/2003 ...
Los Angeles Lakers vs Seattle Super Sonics 07/01/2003 Ignore Tags : mix derrick rose mix miami heat new york knicks mix thunder lebron james ...

Shark warning as white pointers cruise off Perth beaches
Large schools of salmon are bringing danger to Perth's beaches and waters as Great White Sharks follow the fish along the coast.

Footy kicks logic for a nine-pointer
Apart from hilarious change strips, footy’s number one growth industry appears to be inexplicable phenomena

Inside Mail: All the big bets, market movers, work whispers, trial pointers and quaddies for Canterbury ...
ALL the big bets, market movers, work whispers, trial pointers and quaddie tips for Canterbury and analysis of the Group 1s at Flemington on ...

Perth fisherman captures chilling footage of white pointer shark
... joked “the fish became the fisherman” after a close encounter with a shark. Mark Peacock captured chilling footage of the white pointer ramming ...

Canterbury Bulldogs coach Des Hasler calls victory over Melbourne Storm a four-pointer
Bulldogs coach Des Hasler described the victory over the Storm in Melbourne as a "four-point" win.

Resources last updated: 3/23/2016 10:27:10 AM