Learning notes for C/

Source: Internet
Author: User
Tags bitwise function prototype print format

"The function of the static inline function of the C language " "printf print format"
%x Print hexadecimal %d print decimal %b print binary %c print character %s print string %f print single precision float %LF Printing double-precision
Doubles
  "About type conversions in C + +"
dynamic_cast: Typically used when converting between a base class and a derived class, converting a derived class to a base class using this conversion, Run-time cast const_cast: conversion is the const that removes the const variable, Conversions are primarily for const and volatile. Static_cast: A general conversion, similar to a forced type conversion in a C + + +. No run-time check. Usually, if you don't know which one to use, use this. Reinterpret_cast: Used for conversions that do not have any associations, such as converting a character pointer to an integer number.
  "bit field problem"
#include <stdio.h>int main (void) {     struct bs{          unsigned  a:1;   //a  Variable value is 0,1          unsigned b:3 The;  //b  variable takes a value from 0 to 2 of the 3-square -1          unsigned c:4; The   //c  variable takes a value of 0 to 2 of 4 square -1    } bit, *pbit;      bit.a = 1;      bit.b = 7;     bit.c = 15;     printf ("%d,%d,%d \ n", BIT.A,BIT.B,BIT.C);      pbit = &bit;     Pbit->a = 0;      pbit->b &= 3;     pbit->c |= 1;     printf ("%d,% d,%d \ n ", pbit->a,pbit->b,pbit->c);     //printf (" The AAA struct sizeof:%d\n ", sizeof (data));     return 0;}
    "Displacement Operation" << left shift operation
#include <stdio.h>   int main( void ) { size_t a = 2; printf ( "a<<3 =%d\n" , a<<3);                  return 0; }   Result: A * (2*2*2) =
  >> Right Shift operation       #include <stdio.h>         int  mainvoid)     {size_t a = +;printf ("a>>3 =%d\n", a>>3);                 return0;     } Result: A/(2*2*2) = 2   "Avoid duplicate compilation of macro definitions"
#ifndef _test_head_h_ #define _TEST_HEAD_H_ code body ... #endif
"C and C + + mixed compilation macro Definitions"
#ifdef __cplusplus extern "C" {#endif code body ... #ifdef __cplusplus} #endif
"C language annotation standard"
single-line:/** The length of the activequeues array * * Multiple lines:/** the length of the activequeues array * The length of the activequeues array *
/
"Macro definition"
(1), the Windows compiler determines #ifdef WIN32/* If we ' re on Win32, then file descriptors is not nice low densely packed  Integers.     Instead, they is pointer-like windows handles, and we want to use a hashtable Instead of an array to the map FDS to events. */#define EVMAP_USE_HT #endif
(2), macro definition judgment #ifdef evmap_use_ht #include "ht-internal.h" struct event_map_entry;    Ht_head (Event_io_map, event_map_entry); #else #define EVENT_IO_MAP Event_signal_map #endif
  "Bitwise operation"
  1. and operations        And operations are typically used for binary fetching-bit operation , such as the result of a number and 1, is the last digit of the binary. This can be used to determine the parity of an integer, the last digit of the binary is 0 to indicate that the number is even, and the lowest of 1 indicates that the number is odd.  The two digits of the same bit are 1, or 1; if one is not 1, then 0. 00111 11100 (&; or)----------------00100 2. Or OperationAn OR operation is usually used for unconditional assignment on a binary location, such as the result of a number or 1, which forcibly turns the binary lowest to 1.        If you need to change the last binary to 0, the number or 1 will be reduced by one, the practical significance is to force this number to the nearest even.  The same bit as long as one is 1 is 1. 00111 11100 (| or OR)----------------11111 3.  XOR operation XOR symbol is ⊙.        The XOR operation is typically used to reverse a particular one of the binary, because XOR can be defined as: 0 and 1 XOR 0 are unchanged, XOR or 1 are reversed.        The inverse of the XOR operation is itself, that is to say, two times or the same number end result is unchanged, i.e. (a XOR b) xor B = A.        The XOR operation can be used for simple encryption, such as I want to say to my mm 1314520, but afraid of others know, so the two sides agreed to take my birthday 19880516 as a key. 1314520 xor 19880516 = 20665500, I will tell the 20665500 mm. MM again calculates the value of 20665500 xor 19880516 and gets 1314520, so she understands my intentions.  The same bit differs by 1 and the same is 0. 00111 11100 (^ or XOR)----------------11011
  "In-system"      9. Use 16 in the C language as to why the macro definition likes to be defined as 0xf or something, there is often a definition of 0x00000001 in this form. First, the computer operation is all through the 2 binary, so the 16 binary (0x for this number is 16 binary) into 2, then f is 1111.
There is a lesson in the basic C-Language tutorial book, which is bitwise arithmetic, "|", "&", and so on. When an object has several attributes, it can have several properties, such as a piece of clothing, which can be blue (defined blue as 0001 or 0x1), red (defined as red 0010, i.e. 0x2), black (defined as 0100, or 0x4), White (1000,0x8) So when you see this dress, there's a show that tells you that his property is 0xf, that is, 1111, which means 4 colors it all has, if the property is 0xa, that is 1001, that means it has blue and white 2 properties. It's a little more popular .... As for why the macro definition likes to be defined as 0xf, there is often a definition of 0x00000001 in this form. First, the computer operation is all through the 2 binary, so the 16 binary (0x for this number is 16 binary) into 2, then f is 1111. There is a lesson in the basic C-Language tutorial book, which is bitwise arithmetic, "|", "&", and so on. When an object has several attributes, it can have several properties, such as a piece of clothing, which can be blue (defined blue as 0001 or 0x1), red (defined as red 0010, i.e. 0x2), black (defined as 0100, or 0x4), White (1000,0x8) So when you see this dress, there's a show that tells you that his property is 0xf, that is, 1111, which means 4 colors it all has, if the property is 0xa, that is 1001, that means it has blue and white 2 properties. It's a little more popular ....
  "Linked list"
A
linked list (Linked list) is a common basic data structure, a linear table, but does not store data in a linear order, but rather as a pointer to the next node (Pointer) in each node. Fundamentals :
1, single linked list: Each node is stored to the next node of the pointer (Pointer) 2, the circular link list: The chain list is the same as a single linked list , is a chain-like storage structure, the difference is that the loop The pointer to the last node of the list is the first node or header node of the linked list, which forms a chain of loops.
the operation of the cyclic list is basically consistent with the operation of the single-linked list. The differences are as follows: 1. When creating a circular list , the pointer to its last node must point to the table header node instead of NULL as a single- linked list .        This situation is also used to insert a new node after the last node. 2, in determining whether to the end of the table, is to determine whether the value of the node chain is a table header node, when the value of the chain is equal to the table header pointer, the description has reached the end of the table.           Instead of a single- linked list , the value of the chain field is not determined to be null. 3, two-way linked list: Two-way linked list is actually a single- linked list of improvements.
When
we operate on a single- linked list , sometimes you have to work on a direct precursor to a node, and you must start by looking at the table header. This is limited by the structure of the single- linked list node. Because each node of a single- linked list has only one chain domain that stores direct successive node addresses, can you define a chain domain that has a direct successor node address, and a two-link domain node structure that stores the link domain of the direct predecessor node address? This is the doubly linked list .    In the doubly linked list , the node is in addition to the data outside the domain, there are two chain domains, a storage direct successor node address, commonly referred to as the right link domain; A storage direct predecessor node address, commonly referred to as the left chain domain. Design implementation:
  "Stack"
Fundamentals: Last-in-first-out rules 1 sequential stacks: Storing data sequentially using array implementations 2 chain stacks: Using pointers for chained storage data design implementation:
######################################################################################## "Queue"######################################################################################## "Memory allocation"      reallocextern void *realloc (void *mem_address, unsigned int newsize); Syntax:Pointer name = (data type *) realloc (to change the memory size of the pointer name, the new size). The new size must be larger than the original size, otherwise it will result in data loss! header File: #include <stdlib.h> Some compilers require # include <malloc.h>, alloc.h header files can be used in TC2.0 function: First determine whether the current pointer has enough contiguous space, if there is, expand mem_address point to the address, and will mem_address return, if the space is not enough, first according to the size specified by newsize to allocate space, the original data from beginning to end copied to the newly allocated memory area, It then releases the memory area that the original mem_address refers to and returns the first address of the newly allocated memory area. That is, the address of the memory block is redistributed. return value: Returns a pointer to the allocated memory if the reallocation succeeds, otherwise null pointer is returned. Note:The data in raw memory here remains the same. Use the free () function to release memory blocks when memory is no longer in use. Calloc is an ISO C function function name: calloc function prototype: void *calloc (unsigned n, unsigned size), function: allocates n contiguous spaces of size in the dynamic storage of memory, The function returns a pointer to the assigned start address, or null if the assignment is unsuccessful. The difference from malloc: Calloc automatically initializes the memory space after it has been dynamically allocated to zero, and malloc is not initialized, and the data inside is random garbage data.

Learning notes for C/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.