C/C++ Programming Generals
来源:互联网 发布:解压缩软件下载 编辑:程序博客网 时间:2024/06/05 09:35
Lower Language: Instructions that are directly tied to one machine.
Middle level: C/ C++
High level: Matlab
Basic data types:
int: - 2,147,483,648 till 2,147,483,647
unsigned int: 0 till 4,294,967,295
short: - 32,768 till 32767
unsigned short: 0 till 65535
char: -128 till 127
unsigned char: 0 till 255
Write a program to test the biggest number that a short can represent.
For unsigned version:
#include<stdio.h> 2 3 int main(){ 4 unsigned short temp = 1; 5 while(1){ 6 unsigned short tempnew = (temp << 1) + 1; 7 if(tempnew == temp ){ 8 break; 9 } 10 temp = tempnew; 11 } 12 printf("the number is %d",temp); 13 }
For signed version:
#include<stdio.h> 2 3 int main(){ 4 short temp = 1; 5 while(1){ 6 short tempnew = (temp << 1) + 1; 7 if(tempnew < temp ){ 8 break; 9 } 10 temp = tempnew; 11 } 12 printf("the number is %d",temp); 13 }~
About Declaration:
C++ requires forward declaration.
Any label (variable name, function name, class name, etc.) must be declared before using.
This is because C++ executes base on the sequence of written code. C++ program starts from the main function, and flows top to bottom of each functions.
What needs to happen earlier needs to be written before what needs to happen later. Therefore, you need to declare variables before use them.
About text string:
In C++/C, string is implemented by char array. And the char array is special in C/ C++, because there is an ending charter for each array and occupies a 8bit(the last position of char) of the char array. Therefore, if the array is declared as 'char temp[8]', it can only take 7 char and the last one is '0'.
About type casting:
/*usage of type casting*/int a = 10;int b = 100;float ans = a/b;// output of ans is 0;float ans1 = (float) a/b;// output of ans1 is 0.1;float ans2 = (float) a/ (float)b;//output of ans2 is 0.1. float ans3 = a / (float)b;//output of ans3 is 0.1/*However, be careful, the output of*/float ans4 = (float)(a/b);// output of ans4 is 0.
About the format of printf:
- C/C++ Programming Generals
- Java Programming Generals
- Expert C Programming读书笔记
- linux C programming
- The C programming language___1d
- The C programming language___2d
- C++Programming Guidelines
- Programming | Language | C
- C programming language
- C++Programming Guidelines
- Ubuntu C&C++ programming
- Exper C Programming 零零散散
- 读《expert c programming》
- Programming experience in C
- C Programming Language Standard
- The C programming language
- OpenGL with C programming
- C Programming Tips
- 常见算法时间复杂度表
- JVM日志管理统计Runtime中freeMemory,totalMemory,maxMemory
- Eclipse之"任务"管理
- Codeforces Round#375 C:Polycarp at the Radio(贪心)
- go语言的安装和配置,以及包引用
- C/C++ Programming Generals
- 10.4题解
- touch.js
- 缓存雪崩问题
- 谈谈技术学习计划
- go web编程-使用Mux控制路由访问
- yii的relations方法的使用
- spinner 下拉列表
- 主函数main(argc,**argv)中两个参数的用法