auto pAB = dynamic_cast<AB *>(ab); if (pAB) { // if casting succeeded then pointer is not null pAB->show(); }
A *a1 = new A(); *(a1->a1) = 99;
int mat[3][3] = { {0,1,2},{3,4,5},{6,7,8} }; int rows = 3; int cols = 3; int ** matrix = (int**)malloc(rows * sizeof(int*)+ rows * cols * sizeof(int)); matrix[0] = (int*)(((unsigned char*)matrix) + rows * sizeof(int*)); for (int i = 1; i < rows; i++) matrix[i] = (int*)((unsigned char*)matrix[0] + i * cols * sizeof(int)); for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) matrix[i][j] = mat[i][j]; int **ptr = (int **)matrix; printf("%d\n", mat[1][1]); printf("%d\n", matrix[1][1]); printf("%d\n", ptr[1][1]);
char text[100]
char text[100] = "Some text"; for (int i = 0; i < strlen(text); i++) { printf("%c\n",text[i]); }
char text[100] = "Some text"; for (int i = 0; i < strlen(text); i++) { printf("%s\n",&text[i]); }
char* arr[3] = { "geek", "Geeks", "Geeksfor" };
arr[0]
arr[1]
char* arr[3] = { "geek", "Geeks", "Geeksfor" }; // display entire string for (int i = 0; i < 3; i++) { printf("%s\n",arr[i]); } // displays the first character for (int i = 0; i < 3; i++) { printf("%c\n",*arr[i]); } // also displays first character for (int i = 0; i < 3; i++) { printf("%c\n",arr[i][0]); } // displays second character for (int i = 0; i < 3; i++) { printf("%c\n",arr[i][1]); } // Compare that with the previous output for (int i = 0; i < 3; i++) { printf("-----\n"); for (int j = 0; j < strlen(arr[i]); j++) printf("%c\n", arr[i][j]); }
int* arr[5]; for(int i=0; i<5; i++) { arr[i] = (int*)malloc(sizeof(int)); *arr[i] = i; }
int nb_elements = 20; arr[0] = (int*)malloc(sizeof(int) * nb_elements); for (int i = 0; i < nb_elements; i++) arr[0][i] = i;
// Variable in stack int a = 20; // Pointer o that variable int * p = &a; printf("%d\n",*p); // display the value printf("%d\n",p[0]); // display the value int ** pp = &p; // Pointer to pointer - now "pp" contains address of the variable "p" // to access the variable "a" we should use the two times "*" printf("%d\n",*(*pp)); // display the value printf("%d\n",(*pp)[0]); // display the value printf("%d\n",pp[0][0]); // display the value printf("%d\n",*(pp[0])); // display the value