Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Type difference of character literals in C vs C++
In C++ the size of the character constants is char. In C the type of character constant is integer (int). So in C the sizeof(‘a’) is 4 for 32bit architecture, and CHAR_BIT is 8. But the sizeof(char) is one byte for both C and C++.
Example
#includemain() { printf("%d", sizeof('a')); }
Output
4
Example
#includeusing namespace std; main(){ cout Output
1In both cases we are doing the same. But in C sizeof(‘a’) returns 4 as it is treated as integer. But in C++ it is returning 1. It is treated as character.
Advertisements
