C++Primer plus Note(1)

在这里插入图片描述2.
在这里插入图片描述

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	double prices[5] = {5.00,10.00,1.87,7.99,8.49};
	for (double x : prices)
	cout << x << std::endl;
	
	for (double &x : prices)
	{
		 x = x*0.80; //20% off sale
	}
	   
	   
	for (double x : prices)
	cout << x << std::endl;
	
	return 0;
}
  1. 类中的静态变量

由于声明为static的变量只被初始化一次,因为它们在单独的静态存储中分配了空间,因此类中的静态变量**由对象共享。**对于不同的对象,不能有相同静态变量的多个副本。也是因为这个原因,静态变量不能使用构造函数初始化。

// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream> 
using namespace std;




class Apple
{
public:
	static int i;

	Apple()
	{
		// Do nothing 
	};
};


int Apple::i = 1;


int _tmain(int argc, _TCHAR* argv[])

{
	int j;
	cout << "fuck you !" << endl;

	Apple obj1;
	Apple obj2;
	obj1.i = 2;
	obj2.i = 3;
	cout << obj1.i << " " << obj2.i;
	cin >> j;

	return 0;
}

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值