J
Jess
Hello, if I have the following code that has an array of int*:
#include<iostream>
#include<string>
#include<cstring>
#include<cstddef>
using namespace std;
int main(){
int x = 1;
int y = 2;
int z = 3;
int* a[] = {&x,&y,&z};
int* c[] = {&x,&y};
cout << sizeof(a) << endl;
cout << sizeof(c) << endl;
return 0;
}
The output is 12 and 8. "sizeof" is supposed to return the number of
bytes its argument occupies according to its argument type, i.e.
without actually evaluating its argument. Since both "a" and "c" have
type "int**", why does "sizeof" return different values?
Thanks.
#include<iostream>
#include<string>
#include<cstring>
#include<cstddef>
using namespace std;
int main(){
int x = 1;
int y = 2;
int z = 3;
int* a[] = {&x,&y,&z};
int* c[] = {&x,&y};
cout << sizeof(a) << endl;
cout << sizeof(c) << endl;
return 0;
}
The output is 12 and 8. "sizeof" is supposed to return the number of
bytes its argument occupies according to its argument type, i.e.
without actually evaluating its argument. Since both "a" and "c" have
type "int**", why does "sizeof" return different values?
Thanks.