Note_20150204_C++ Basics

来源:互联网 发布:如何安装网络监控 编辑:程序博客网 时间:2024/05/02 04:33

Just as what I have state, this is just my own note.


1. All C++ programs must have a main() function, and it is there that program execution begins.

2. All variable must be declared before they are used.

3. C++ supports a variety of data types, including integer and floating point. (All right, WTF, there is no fixed-point)

4. The output operator is <<, and when used with cout, it causes information to be displayed on the screen.

5. The input operator is >>, and when used with cin, it reads information from the keyboard.

6. Program execution stops at the end of main().



In C++, one function cannot be embedded within another function. But could call.


A prototype declares a function prior to its first use.


A parameter is a variable defined by a function that receives an argument.


The term argument refers to the value that is used to call a function. The variable that receives the value of an argument is called a parameter. In fact, functions that take arguments are called parameterized function.


//Returning a value example.


#include<iostram>

using namespace std;


int mul(int x, int y);


int main()

{

  int answer;

  answer = mul (10,11); //assign return value

  cout << "The answer is " << answer;


  return 0;


}


int mul(int x, int y)// here we declare the return typing and the function name, its parameter

{

 return x*y;//return product of x and y

}




The General Form of C++


return-type function-name(parameter list)

{

 body of the function


}




Global Variable: Make a variable and its data stay in existence throughout the entire execution of the program.


\b-------backspace

\f--------form feed

\n--------newline

\r--------carriage return

\t--------horizonal tab

\"--------double quote

\'--------single quote character

\\--------backslash

\v--------vertical tab

\a--------alert

\?--------?

\N--------octal constant

\xN--------hexadecimal constant



C+has three general classes of operators: arithmetic, relational and logcial, and bitwise.


The modulus operator % also works in C++ in the same way that it does in other languages. Remember that the modulus operation yields the remainders of an integer division.


A one-dimensional array is a list of related variables.         type var_name[size]





0 0
原创粉丝点击