Types of Variables, Assignment, printf, Tracing, Watch Window,Sizeof

Computer Memory

  1. RAM: Random Access Memory
    Stores data temporally for use.

  2. Bit:
    “Binary Digit” –The smallest unit of information on a machine…
    (Single bit holds 0 or 1)

  3. Byte:
    1 byte contains 8 bits.

Types of Variable:
在这里插入图片描述在这里插入图片描述

Declaring Variables & Variable Assignment:

在这里插入图片描述

Notice:
age = 18 means set age to 8 (from right to left)
y=x=5
is x=5 -> y=x (this style is better to debugger)

Debugger (on Watch Window)

Place a breakpoint
在这里插入图片描述
Press F5 to runs the program with the debugger (orange status bar at the bottom)
The name & value & type of variable be showed on the watch window (down-left)

在这里插入图片描述
Press F10 let the compile run the 6th line and watch window will change with it
(Run time can also be showed on the right of line)
在这里插入图片描述
Modulus: %

a % b
example: 7 % 2 means divide 7 by 2 and keep remainder (1)
在这里插入图片描述

If b > a just keep left (a):
在这里插入图片描述

Shorthand (Reduce the frequency of using memory)

f = f + 5 -> f += 5 f = f + 1 -> f++
f = f – 5 -> f -= 5 f = f - 1 -> f–
f = f * 5 -> f *= 5
f = f / 5 -> f /= 5

Prefix & Postfix
Int h = g++ ( assign the value of g to h, then post-increment happen)
Int j = ++i ( pre- increment happen, then assign the value of i to j)

Output the value (printf)
Add type of value and the name of variable on printf (do not miss the comma)
在这里插入图片描述

Literals (Constants)
A fixed value that cannot change during the execution of the program
在这里插入图片描述sizeof
Use sizeof to check the type of the variable and how many bytes of it.
(To calculate the size of these type)
在这里插入图片描述
在这里插入图片描述

Practice:
Requirements
Write a program that reads a Fahrenheit degree in as a real number, and then converts the input into Celsius. The program must then display the resulting temperature as Celsius.

在这里插入图片描述

Design
Printf(“…. converter”)=>printf(“pls enter….”)=>declare variables=>scanf(“temperature”)=> declare Celsius=>Celsius = (5 ÷ 9) x (Fahrenheit – 32)=> printf (……same as….“)=>printf(“….degrees Celsius”)

Implementation
在这里插入图片描述

Testing
在这里插入图片描述
Errors Encountered
Failure
在这里插入图片描述

Debugging
Forgot to use address
在这里插入图片描述

Because the %10f .There is no need to have %10f (compile will keep numbers after point),
在这里插入图片描述

Should use 5.0f, because if there are two integers in division, compile will only keep integer result
在这里插入图片描述

Lessons Learnt:
if there are two integers in division, compile will only keep integer result
do not forgot to use address on scanf.
%f is typically enough for float.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值