-4

The following code gives output as 1, 4, 4 in C whereas 1, 1, 4 in C++

#include<stdio.h> 
int main() 
{  
    char ch = 'A'; //initialise 
    //printing output
    printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));    
    return 0; 
} 

1 Answers1

9

Because a character literal is of type int in C but of type char in C++.

wilx
  • 17,697
  • 6
  • 59
  • 114