Does the working of sizeof operator different in c andd c++

c, c++

Solution

It's nothing to do with the `sizeof` operator in particular; rather, the size of character literals in C is different than C++, because character literals in C are of type `int`, whereas in C++ they are of type `char`.

See Why are C character literals ints instead of chars? for more information.

Problem

I have written a small printf statement which is working different in C and C++: ``` int i; printf ("%d %d %d %d %d \n", sizeof(i), sizeof('A'), sizeof(sizeof('A')), sizeof(float), sizeof(3.14)); ``` The output for the above program in c using gcc compiler is 4 4 8 4 8 The output for the above program in c++ using g++ compiler is 4 1 8 4 8 I expected 4 1 4 4 8 in c. But the result is not so. The third parameter in the printf sizeof(sizeof('A')) is giving 8 Can anyone give me the reasoning for this

Original source

Related problems