
- 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
Data type of character constants 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
- Difference between C++ string constants and character constants
- What are C++ Character Constants?
- How to define character constants in C#?
- Character constants vs String literals in C#
- What are Backslash character constants in C language?
- Type difference of character literals in C and C++
- Type difference of character literals in C vs C++
- Get the array of the values of the constants in the current enum type in C#
- Need of long data type in C
- Data Type Ranges and their macros in C++
- Is there any need of “long” data type in C and C++?
- size_t data type in C
- C Program to check the type of character entered
- What is data storage? the terms data objects, variables, and constants concerning data storage?
- C program for testing the character type

Advertisements