【C++ Introduction and Basic】

Becoming an expert won’t happen overnight, but with a little patience, you’ll get there.

Programming Languages

Machine Language

Assembly Language

High-level Languages

  • compiler
  • interpreter

Most languages can be compiled or interpreted, however, traditionally languages like C, C++, and Pascal are compiled, whereas “scripting” languages like Perl and Javascripttend to be interpreted. Some languages, like Java, use a mix of the two.


C/C++

  • C++ (pronounced see plus plus) was developed by Bjarne Stroustrup at Bell Labs as an extension to C, starting in 1979.

  • C++’s claim to fame results primarily from the fact that it is an object-oriented language.

  • C++ was standardized in 1998 by the ISO committee .

  • C++ excels in situations where high performance and precise control over memory and other resources is needed.


Introduction to C++ development

在这里插入图片描述


First Program

#include <iostream>

int main(){
    std::cout << "Hello World!";
    return 0;
}
> g++ .\01_test.cc -o 01_test
> .\01_test.exe

Introduction to objects and variables

Data

data is any information that can be moved, processed, or stored by a computer.

Objects and variables

In order to create a variable, we use a special kind of declaration statement called a definition .

int x; // define a variable named x, of type int

Data types


Variable assignment and initialization

assignment

#include <iostream>

int main()
{
    int width;
    width = 5; // copy assignment of value 5 into variable width

    // variable width now has value 5

    width = 7; // change value stored in variable width to 7

    // variable width now has value 7

    return 0;
}

initailization

int a; // no initializer
int b = 5; // initializer after equals sign; Copy initialization
int c( 6 ); // initializer in parenthesis; Direct initialization
int d { 7 }; // initializer in braces; Brace initialization

Introduction to iostream: cout, cin, and endl

std::endl vs ‘\n’

Using std::endl can be a bit inefficient, as it actually does two jobs:

  • it moves the cursor to the next line
  • it “flushes” the output

eg:

#include <iostream>

int main(){
    int x;
    std::cin >> x;
    std::cout << x;
    return 0;
}
cincout
1212
fdffd0
12fjlakj12

Introduction to literals and operators

  • A literal (also known as a literal constant) is a fixed value that has been inserted directly into the source code.
  • In mathematics, an operation is a mathematical calculation involving zero or more input values (called operands) that produces a new value (called an output value).
  • Operators in C++ come in three different arities:
    • unary
    • binary
    • ternary

Introduction to expressions

An expression is a combination of literals, variables, operators, and function calls that can be executed to produce a singular value.


人呢?都是跟自己较真过不去。
我也不知道我为什么要非要看英文的学习。
但就是一边自我怀疑,一边硬着头皮学。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值