lec1-Introduction

lec1 Introduction

1 Compiled Language and C++

  • Concisencess
  • Maintianability
  • Portability
  • gcc
    g++ filename -o objectname

2 Hello World

#include <iostream>

int main() {
    std::cout << "Hello, world!\n";
    
    return 0;
}
  • keywords
    Word with special meaning to the complier
    int, double, for, auto
  • Identifiers
    Names of things that are not built into the language
    cout, std, x, myFunction
  • Literals
    Basic constant values whose value is specified directly in the source code
    "Hello, world!", 24.3, 0, 'c'
  • Operators
    Mathematical or logical operations
    +, -, &&, %, <<
  • Punctuation/Separators
    Punctuation defining the structure of a program
    {} () , ;
  • Whitespace
    Spaces of various sorts; ignored by the complier
    Spaces, tables, newlines, comments
  • Comments exist to explain non-obvious things going on in the code. /* multilines */
    // singleline
  • Preprocessor to dump in the contents of another file

include

  • Outputting some piece of text to the screen.
    cout <<
  • Namespace
    identifiers can be defined within a context-sort of a directory of names
    using namespace std;
    std::
  • Escape sequences
    \a, \b, \f, \n, \r, \t, \, ', ", \some interger x
  • return 0
    indicates that the program should tell the oprating system it has completed successfully. This syntax will be explained in the context of functions

3 Basic Language Features

  • values and statements
  • operators
  • data types
    char-1 byte
    int-4 bytes
    bool-1 byte
    double-8 bytes

4 Variables

#include <iostream>
using namesapce std;

int main() {
    int x;
    x = 4 + 2;
    cout << x / 3 << ' ' << x * 2
    
    return 0;
}
  • The name of a variable is an identifier token. Identifiers may contain numbers, letters, and underscores( _ ), and may not start with a number
  • a single statement that does both declaration and initializaiton
    int x = 4 + 2;

5 Input

#include <iostream>
using namespace std;

int main() {
    int x;
    cin >> x;
    
    cout << x / 3 << ' ' << x * 2;
    
    return 0;
}
  • << is the syntax for outputting values, cin >> is the syntax for inputting values
  • if you have trouble remembering which way the angle brackets go for cout and cin, think of them as arrows pointing in the direction of data flow. cin prepresents the terminal, with data flowing from it to your variables; cout like wise represents the terminal, and your data flows to it.

6 Debugging

  • Two kinds of errors: compilation errors and runtime errors Compilation errors are problem raised by the compiler, generally resulting from violations of the syntax rules or misuse of types. These are often caused by typos and the like. Runtime errors are problems that you only spot when you run the program: you did specify a legal program, but it doesn't do what you wanted it to. These are usually more tricky to catch, since the compiler won't tell you about them
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,167评论 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    网事_79a3阅读 14,289评论 3 20
  • 《管理的觉醒》-64 正文: 归宿感能激发整个团队的战斗力。当每一个团队每一个小的独立合算单位都有超出的利润,都有...
    合肥李风丽阅读 4,262评论 3 0
  • 许多人没有听说过麦秸秆画,许多人也没有见过麦秸秆画。麦秸秆,小麦成熟后脱粒剩下的“树干”,一支麦秸秆支撑一个麦穗。...
    凡尔娜阅读 2,523评论 0 4
  • 内容简介 这个系列主要是讲述的是一位居住在通惠河的女龙王以及她的小跟班——一只橘猫和一条狗所发生的逗比日常,内容搞...
    肖遥哥哥脑洞故事阅读 3,720评论 1 1

友情链接更多精彩内容