Modrá je dobrázelená je lepšíLopuch.cz
#include <stdio.h> template<int n> void foo(int (&arr)[n]) { int sz = sizeof(arr); printf("size: %d\n",sz); } int main(int c, char **v) { int a[40]; foo(a); }
ondra@linda:/tmp$ g++ test.cpp -o test ondra@linda:/tmp$ ./test size: 160 ondra@linda:/tmp$
template<int n> void fce(int pole[n]) { int a; a = sizeof(pole); }
void add (A **array) { A* newA = malloc(sizeof(A)); newA->structB.value = 12345; array[1] = newA; }
#include "stdio.h" #include "stdlib.h" struct b { int value; }; struct a { struct b structB; }; typedef struct a A; void add (A **array) { A newA; newA.structB.value = 12345; array[1] = &newA; } A *pointers[5]; int main (void) { add (&*pointers); printf("%d\n", pointers[1]->structB.value); // Vypise 12345 -> spravne printf("%d\n", pointers[1]->structB.value); // Vypise nesmysl (pravdepodobne adresu v pameti), proc? getchar(); return 0; }