
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Type difference of character literals in C and 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
#include<stdio.h> main() { printf("%d", sizeof('a')); }
Output
4
Example
#include<iostream> using namespace std; main() { cout << sizeof('a'); }
Output
1
In 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.
- Related Articles
- Type difference of character literals in C vs C++
- What is the difference between character literals and string literals in Java?
- What are Character Literals in C++?
- What is the type of string literals in C and C++?
- Character constants vs String literals in C#
- What is the type of string literals in C/ C++?
- Data type of character constants in C and C++
- Literals in C#
- Integer literals vs Floating point literals in C#
- C Program to check the type of character entered
- Compound Literals in C
- Octal literals in C
- C program for testing the character type
- Difference between C++ string constants and character constants
- What is the difference between type conversion and type casting in C#?

Advertisements