Compilation

Getting error when trying to compile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 #include<iostream>



void sizes(char ch, int i, int* p)
{

   std::cout<< "the size of char is " <<sizeof(char)<<' '<<sizeof (ch)<< '\n';
   std::cout<< "the size of int is " <<sizeof(int)<<' '<<sizeof (i)<< '\n';
   std::cout<< "the size of int* is " <<sizeof(int*)<<' '<<sizeof (p)<< '\n';

}


int main()

{

    char a = 'a';
    int x = 8, z = 9;
    

    sizes('a', x , z);

}




I don`t know how to compile, there was in my book " Execute the example above and see what you get" .
The last argument that sizes() expects is a pointer to an integer, while you're passing an integer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include<iostream>



void sizes(char ch, int i, int* p)
{

   std::cout<< "the size of char is " <<sizeof(char)<<' '<<sizeof (ch)<< '\n';
   std::cout<< "the size of int is " <<sizeof(int)<<' '<<sizeof (i)<< '\n';
   std::cout<< "the size of int* is " <<sizeof(int*)<<' '<<sizeof (p)<< '\n';

}


int main()

{

    char a = 'a';
    int x = 8;
    int* pi = &x;
    

    sizes('a', x , pi );

}





Output:

the size of char is 1 1
the size of int is 4 4
the size of int* is 8 8


This is normal? I had to determine the size of char, int and int* ...
Why not normal?
Looks normal for a 64-bit compiler, yes.
Topic archived. No new replies allowed.