[Notes] - C / C ++ in a little note (point to note)

C / C ++ in a little note (note the point)

type of data

  1. Two integers obtained by dividing or an integer;
    as long as there is a float, floating point result
    for example:
3 / 2 = 1;
3.0 / 2 = 1.5;

Using the input and output

  1. scanf ( "% d", & a); // Do not forget &;
  2. scanf ( "% d", & arr [b]); do not write scanf ( "% d", & arr [b]); that is, before and after the% d more than a different result this space;
  3. Enter written while (gets (arr)) instead of while (gets (arr)! = EOF)
  4. Data and more time can not use cout cin
  5. In the scanf format string, "% s" indicates a character string is to be input. Note that when using scanf input string, the input string can not have spaces, otherwise it is read that part of the space is in front of the entrant.
  6. If you want the user input contains an even more spaces of an entire row, are read as a string, you should use gets ();

Format control character

  1. % S% c for a single character string
  2. a double input output% f% lf
  3. long input and output% ld long long input-output% lld
  4. % D to output an integer
  5. % C to output a character
  6. % S to output a string
  7. % X to output a hexadecimal integer
  8. % U to be outputted as an unsigned integer (positive integer)
  9. % F to output a floating point number.

loop statement

  1. while loop
	while (a) {
	}
//要防止死循环   大括号里面要有表达式去改变小括号内的表达式返回值;
  1. for loop
	for(   ;     ;   )     { 

	}
//第一个语句  用来初始化  一开始执行一遍;
//第二个语句  用来判断是否继续循环   相当于while判断;
//第三个语句  每次循环结束会执行一遍   一般用来改变第二个语句的真假;
  1. Recursive and loop difference is that the cycle is the implementation of a code, only different parameters; recursive call to be yourself.
    Analogy:
    the cycle in the same place as spin; recursion is entered layer by layer, and then backtrack, although each layer are the same.
  2. Recursive to pay attention to a process of

Array

  1. Generally used to process multiple data array will need to save up kind of like ordering
  2. Can not be wrong not to use an array of
  3. Index array elements, may be any integer, can be negative, it may be larger than the number of elements in the array.
    Then, a [-2] What is the meaning of it? If a start address of the array is n, a [-2] at address n + represents a variable int (-2) * size (int) at. This is unsafe.
    To access the array element is not in the storage array, a phenomenon called "array bounds."
    Unless there is a special purpose, generally we do not write like an [-2] = 5 so obviously out of bounds statement. But we often use as a subscript of array elements with expressions containing variables. Value of this expression may be turned into a negative number, greater than or equal to the length of the array. This will cause the array bounds.

One-dimensional array

  1. Type name array name [element number];
    where "number of elements" must be a constant or a constant expression is not a variable, and its value must be a positive integer. The number of elements are also referred to as "length of the array."
  2. T array[ N ];// T here can be any type name, such as char, double, int and so on. N is a positive integer
    // value or a positive integer constant expression then we define an array, the array is the name of the array. array array of N elements, each element is a variable of type T. This N elements in the memory is stored in a row next to each other. array occupies a continuous array, the size of a total of N × sizeof (T) bytes of storage space.
    The index when the decimal, the compiler will automatically go to the end rounding.

Two-dimensional array

  1. T array[N][M];// T here can be any type name, such as char, double, int and so on. M, N is a positive integer //, or a positive integer constant expression is so, we defined a two-dimensional array, the name of the array is the array. array has N × M array elements, each element is a variable of type T,. This N × M elements in memory is stored in a row next to one another. array occupies a contiguous array, a total storage space size of N × M × sizeof (T) bytes.

function

  1. int min(int x, int y); // 返回值类型为 int,有两个整型参数,函数名为 min
  2. double calculate( int a, double b); // 返回值类型为 double,有一个整型参数,一个 double 型参数,函数名为 calculate
  3. char judge(void); // 返回值类型为 char,没有参数,函数名为 judge
  4. void doit(int times); // 返回值类型为 void,表示不返回任何值,有一个整型参数,函数名为 doit

Local and global variables

  1. If a local variable and a global variable of the same name, then the scope of the local variable, function local variables, global variables does not work.

pointer

  1. If you define:
    T * p ;// T can be any type of names, such as int, double, char, and so on. Hereinafter encountered // "T" are also what it means then the variable p is a "tag" (referred to as the "Guidelines"), p type is T *, the expression "* p" is of type T. And by the expression "* p", we can read and write sizeof starting from address p (T) bytes. In layman's terms, is to be believed, "* p", this expression is equivalent to a T type stored in an address at p variables. Shows the expression "P *" in the "*", referred to as "indirect reference operator."
  2. Keep in mind that, regardless of what type T represents, sizeof value (T *) is 4. That is, all pointer variable, no matter what type it is, and its footprint is four bytes.
  3. Pointer of common usage are: the address of a variable of type T x, and assigned to a pointer of type T * p (commonly known as "Let point x p"), after which the expression "* p", which represents the variable p points (i.e. x), the value can be read or modified by the variable x "* p".
    For example like this:
char ch1 = ’A’;  // (1) 
char * pc = &ch1; // (2) 使得 pc 指向变量 ch1 
* pc = ’B’;   // (3) 执行效果是使得 ch1 = ’B’ 
char ch2 = * pc; // (4) 执行效果是使得 ch2 = ch1 
pc = & ch2;   // (5) 使得 pc 指向变量 ch2。 
			  //  同一指针在不同时刻可以指向不同变量 
* pc = ’D’;   // 语句 6,执行效果是使得 ch2 = ’D’ 
  1. General summary of the law, if you define: T ** p; // T here can be any type name then p will be called "pointer to a pointer." this pointer p, which is a type T **, the expression "* p" is a type of T *, "* p" denotes a pointer of type T *. Similarly, int *** p; int **** p; int ***** p; and so, no matter how many intermediate "*" are legal definition.

I do not know on there, put here pair of

  1. Enter also the character;
  2. <1> with Euclidean greatest common divisor
    algorithm description:
    m n of the remainder is a, if a is not equal to 0
    then the m <- n, n <- a, remainder continued
    or greatest common divisor n
    <2> = the least common multiple of the two numbers volume / greatest common divisor;
  3. Problems can try to use the data are output again and see where expectations are not the same know what went wrong
  4. Note that spaces, line breaks some of the problems only when the space between the two numbers, not a number followed by a space.
  5. After entering the number is not displayed , it may be disclaims similarint long
  6. Does not exceed 32-bit integer, it is for use int type stored in another way.
  7. A character occupies two bytes
  8. A letter or number to occupy one byte.
  9. getchar () can be absorbed carriage
  10. He did not explain the general topicchar arr[1005]
  11. Greedy algorithm that is locally optimal choice at every step to achieve the overall optimum.
  12. Note Fibonacci number of deformation problems
  13. The integer is located is set to an integer (e.g., in the loop i, j to declare the data type is an integer type).
  14. In programming competition, we have a common header file:
    #include <bits/stdc++.h>
      found it to be part of the C ++ in support of an almost universal header file that contains all available to the C ++ library functions, such as <istream>/<ostream>/<stack>/<queue>.
    in programming competitions, the use of this header is a good the idea, especially when you want to select the first file in less time, we are more focused on finding algorithm to solve the problem rather than software engineering. From the perspective of software engineering, we'd better minimize include the header files, if you include some you might not use the header file, the compiler will add unnecessary time and program size.
    bits/stdc++The drawback
    bits/stdc++.his not the standard GNU C ++ library header files, so if you are in some compilers (except GCC) compiler on your code may fail, such as MSVC do not have this header file.
    Use it will contain a lot of unnecessary things, and will increase the compile time
    part of the C ++ header file is not standard, it is not portable, should be avoided.
    Although there are some common standard header files, but still should avoid using it to replace the specific headers, because the compiler are actually read and parse each header file at each compilation contains conversion unit (including recursive comprising header files).
    bits/stdc++Advantages
    in the game, using this file is a good idea, when you want to reduce waste time to choose the time; especially if your ranking is very time-sensitive time.
    This also reduces the preparation of all necessary header files of all chores.
    You do not have to remember to use every function of all the STL GNU c ++.
  15. When using the C ++ programming language if the display on the OJ error C2679: binary ">>": not found acceptable the right number of "std :: string" type of operation operator , then it will add or change the header file#include <string>
  16. Computer, with all values represent and store complement of.
发布了34 篇原创文章 · 获赞 2 · 访问量 878

Guess you like

Origin blog.csdn.net/Kapo1/article/details/104089192