Projects and solutions
Projects: An container to hold every necessary component of a certain program. All files are stored in the relative project folder, including auxiliary data files, source file.
Solutions: An container to hold multiple of projects. An mechanism to integrate 1 or more programs and other resources together. Solution will store many project-related folders. Adding more projects in 1 Solution is possible but in most cases we add project which only has relationships with other projects in Solution.
Console application
Precompile head file. Application wizard will generate head file 'stdafx.h' including precompile declarations(#include ...)
Program using Unicode, add
#define _UNICODE
#define UNICODE
in stdafx.h
instead of main(), using wmain() if you about to use _UNICODE
type of variable: auto
'auto' is a kind of type that can be deduced from the initial value that has been assigned to the variable. Obviously a initial value is necessary if you about to use 'auto'.
auto shall not use with initialization list in the same time:
auto n{16};
which is wrong.
the real type of n in the statement is std::initializer_list
auto n(16);
is of no problem
define type: typeid
get the type of a certain expression. typeid(expression).name()
how to get global variables in a code block?
scope resolution operator
cout<<::global variable name
pointer
- pointer for multi-dimension array set a pointer address to the 1st element of a same dimension array
double beans[3][4];
double* pbeans;
pbeans=&beans[0][0];
set a pointer address to row
double beans[3][4];
//double* pbeans; error because beans is a 2d matrix address, and pbeans type is double*;
double (*pbeans[4]); //pbeans type is pointer of a 4-element array;
pbeans= beans;
- function declaration (prototype)
- To declare a function when using it in the source file happens before the definition.
- Using a more meaningful form argument in the declaration to make a better understanding of the function. When call of the function use a simple version of argument.
- transfer array name
a 2D array
beans[3][4]
is defined
- transfer double* type as argument
void print_array(double a[], int r, int c)
{
int num{ 0 };
for (int i{}; i < r; i++)
{
for (int j{}; j < c; j++)
{
cout << setw(6) << *(a + num++);
}
cout << endl;
}
}
call of:
print_array(beans[0],3,4);
- transfer double*[4] as argument
void yield(double a[][4], int n)
{
for (int i{}; i < n; i++)
{
for (int j{}; j < 4; j++)
{
cout << setw(5) << a[i][j];
}
cout << endl;
}
}
call of:
yield(beans, _countof(beans));
Top comments (0)