- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Standard Size of character ('a') in C/C++ on Linux
In C++ the size of the character literal is char. In C the type of character literal 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 Code
#include<stdio.h> main() { printf("%d", sizeof('a')); }
Output
1
Example Code
#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 an integer. But in C++ it is returning 1. It is treated as a character.
Advertisements