C/C+中的每一个常亮(every literal)都是有类型的,例如10 就是int型的,因此siziof(10)和sizeof(int)是相同的,但是字符型常亮(‘a’)在C和C++中有不同的变量类型。

在C中,‘a’被认为是int形,在C++中,‘a’被认为是char型。

int main()
{
printf("sizeof('V') = %d sizeof(char) = %d", sizeof('V'), sizeof(char));
return ;
}

结果:

C result – sizeof(‘V’) = 4 sizeof(char) = 1

C++ result – sizeof(‘V’) = 1 sizeof(char) = 1

上述行为也可以体现C++的函数重载

void foo(char c)
{
printf("From foo: char");
}
void foo(int i)
{
printf("From foo: int");
} int main()
{
foo('V');
return ;
}

则调用void foo(char c)

3) Types of boolean results are different in C and C++.

// output = 4 in C (which is size of int)
printf("%d", sizeof(==)); // output = 1 in c++ (which is the size of boolean datatype)
cout << sizeof(==);

[C/CPP系列知识] Type difference of character literals 和 bool in C and C++的更多相关文章

  1. Type difference of character literals in C and C++

    Every literal (constant) in C/C++ will have a type information associated with it. In both C and C++ ...

  2. [C/CPP系列知识] 那些程序C语言可以编译通过但C++无法编译成功 Write a C program that won’t compile in C++

    http://www.geeksforgeeks.org/write-c-program-wont-compiler-c/ 1) C++中在函数声明之前调用一个函数会引发错误,但是在C中有可能可以. ...

  3. [C/CPP系列知识] C++中extern “C” name mangling -- Name Mangling and extern “C” in C++

    http://www.geeksforgeeks.org/extern-c-in-c/ C++函数重载(function overloading),但是C++编译器是如何区分不同的函数的呢?----是 ...

  4. [C/CPP系列知识] 在C中使用没有声明的函数时将发生什么 What happens when a function is called before its declaration in C

    http://www.geeksforgeeks.org/g-fact-95/ 1 在C语言中,如果函数在声明之前被调用,那么编译器假设函数的返回值的类型为INT型, 所以下面的code将无法通过编译 ...

  5. WebApi系列知识总结

    WebApi系列知识 一.webApi项目搭建 1.新建WebApi项目 (1) (2) (3) (4) Areas – HelpPage – App_Start – HelpPageConfig.c ...

  6. 通俗化理解Spring3 IoC的原理和主要组件(spring系列知识二总结)

    ♣什么是IoC? ♣通俗化理解IoC原理 ♣IoC好处 ♣工厂模式 ♣IoC的主要组件 ♣IoC的应用实例 ♣附:实例代码 1.什么是IoC(控制反转)? Spring3框架的核心是实现控制反转(Io ...

  7. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  8. 【ARM】arm系列知识框架

    [ARM编程模型] 硬件: 电路原理图 软件: 体系结构, 指令集, 寄存器组 [ARM编程技术] 汇编/C语言 编译, 链接, 烧写和调试 windows: MDK linux  : gcc [AR ...

  9. 【python问题系列--1】SyntaxError:Non-ASCII character '\xe5' in file kNN.py on line 2, but no encoding declared;

    因为Python在默认状态下不支持源文件中的编码所致.解决方案有如下三种: 一.在文件头部添加如下注释码: # coding=<encoding name> 例如,可添加# coding= ...

随机推荐

  1. 密码强度的js插件(完成)

    效果如下图: 低:

  2. js高程笔记1-3章

    第1章 js简介 1.js由三部分组成,ECMAScript, DOM, BOM. 第2章 在HTML中使用js 1.把<script>标签放在<body>里面的最后,可以在加 ...

  3. Change http port in bitnami stack

    My case goes like this. I installed bitnami redmine first with port 80 for http service, but got pro ...

  4. [C/C++]在头文件中使用static定义变量意味着什么

    文章出处:http://www.cnblogs.com/zplutor/ 看到有一位同学在头文件中这么写: static const wchar_t* g_str1 = - static const ...

  5. IIS目录下文件共享后System.IO.File.Exists返回false

    场景:在iis目录下,因为特殊需要共享一个文件夹,给到其他的技术人员访问,突然发现小小的操作,搞“大”了,使用 string path = Server.MapPath("~/file/te ...

  6. 例题6-4 Broken Keyboard UVa11988

    题目分析: 起初这道题目没有做出来,原因是我一直想把整块区域一并插入,而不是逐个插入.今后做题应该注意这个问题,把问题分解去考虑,也许会少走许多弯路. 下边附上AC代码 #include <cs ...

  7. ios特性访问器方法(setter和getter)

    Employee.h @interface Employee:NSObject { int _employeeNumber; NSString *_name; Employee*_supervisit ...

  8. Virtualbox中安装Openwrt

    Virtualbox:https://www.virtualbox.org/wiki/DownloadsOpenwrt:http://downloads.openwrt.org/backfire/10 ...

  9. 【python】为什么用python

    python胶水语言.脚本语言之王,C/C++可以写python的module,标准库里就有用C/C++写的东西,这个跟java的JNI类似. 性能好,易调试: since 91年

  10. swift UIAlertController教程

    在iOS8中,UIAlertView与UIActionSheet都已经退休,取而代之的是UIAlertController!它的使用示范如下://弹出一个警告框,标题是“提示”,信息是“我的博客:oa ...