hello guys,
i had a little problem in understand the pointer to pointer reference concept (i.e **p) how it is used. and what is the effect of uisng that.
any help will be appreciated
hello guys,
i had a little problem in understand the pointer to pointer reference concept (i.e **p) how it is used. and what is the effect of uisng that.
any help will be appreciated
Try reading through this post. It was discussed decently there. Let me know if you have any questions.
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
Think of **p as p[][]. A multidimensional array (even though technically it's not).
Code:const char **p = { "Apples", "Cornbread" }; // p[] would carry the strings // p[][] would carry the characters of the strings // *p would carry the strings // **p would carry the characters of the strings p[0][0] = 'B' // Change Apples to Bpples **p = 'C' // Change Bpples to Cpples
Does any of that work?
I very much doubt it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You mean because of const, or because they're string literals. Or both.
Quzah.
Hope is the first step on the road to disappointment.
This is crazy horse !
Code:#include <stdio.h> #include <stdlib.h> #include <string.h> int main( void ) { // Create a string array char p[2][100]; // Copy the strings into the string array strncpy( p[0], "Apples", sizeof( *p ) ); strncpy( p[1], "Corn Bread", sizeof( p[0] ) ); // Next is the same thing as: // **p = 'B' p[0][0] = 'B'; // Change Apples to Bpples puts( p[0] ); // Next is the same thing as: // p[1][5] = 'X' *( ( *( p+1 ) )+5 ) = 'X'; // Change Corn Bread to Corn Xread puts( p[1] ); return 0; }