---
title: "+-的类型转换"
author: "paramore"
date: "2012-02-28T15:28:09Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-02-28T15:28:09Z"
id: 1430018
url: "https://paramore.iteye.com/blog/1430018"
---

c中变量间赋值可能会出现类型转换的情况，而+-可以进行类型转换，如下代码1：

 

short a = 1;

a += 1L;

编译不会出错；而代码2：

short b = 1;

b = b + 1L;

需要进行强制类型转换，否则会编译出错：

b =（short）( b + 1L);