C++笔记(一)

void  fun()
{
      bool a = true ;
      bool b = true ;
      bool x = a +b ; // a+b is 2, so x becomes true
     bool y = a | b ; // a | bis 1, so y becomes true
}

 

A pointer can be implicitly converted to a bool. A nonzero pointer converts to true ; zerovalued pointers convert to false.

 

A type wchar_t is provided to hold characters of a larger character set such as Unicode.

 

A literal starting with zero followed by x (0x) is a hexadecimal (base 16)number. A literal starting with zero followed by a digit is an octal (base 8) number. For example:
                         decimal :          0      2       63      83
                         octal:               00    02     077   0123
                         hexadecimal:  0x0  0x2  0x3f   0x53

 

By default, a floating-point literal is of type double .

 

If you want a floating-point literal of type float, you can define one using the suffix f or F.

 

#include <iostream>
#include <limits>

using namespace  std;

int main()
{
 cout << "largest float == " << numeric_limits<float>::max()
  << ", char is signed == " << numeric_limits<char>::is_signed << endl;
 cout << "specialized(char): " << numeric_limits<char>::is_specialized << endl;
}

If no initializer is specified, a global, namespace, or local static object (collectively called static objects) is initialized to 0 of the appropriate type. Local variables (sometimes called automatic objects) and objects created on the free store (sometimes called dynamic objects or heap objects) are not initialized by default.Members of arrays and structures are default initialized or not depending on whether the array or structure is static. Userdefined types may have default initialization defined.

 

Objects declared in global or namespace scope and statics declared in functions or classes are created and initialized once (only) and ‘‘live’’ until the program terminates.

 

Another use of a typedef is to limit the direct reference to a type to one place. For example:
                    typedef  int  int32;
                    typedef  short  int16;

If we now use int32 wherever we need a potentially large integer, we can port our program to a machine on which sizeof(int) is 2 by redefining the single occurrence of int in our code:

                    typedef  long int32;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值