iOS interest Class (ii)

Source: Internet
Author: User

C Language:

1. Data type

The data types of C include:

Integer (int), character (char), floating point (single (float), double-precision (double)), Boolean (bool), enum-type (enum), array-type (arr[]), struct-type (struct), pointer-type (*P), and null-type.

2. Constants and variables

(1) A constant whose value is immutable, and the symbolic constant name is usually capitalized.

(2) A variable is named with an identifier, and its value is the amount that can be changed.

(3) An identifier is a sequence of letters, numbers, or underscores that begin with a letter or underscore, and note that the first character must be a letter or an underscore, otherwise an illegal variable name. The variable is assigned the appropriate storage unit at compile time.

3. Arrays

(1) If a variable name is followed by a square bracket with a number, the declaration is an array declaration. Example: int arr[5];

(2) A string is also an array. They end with an ASCII null as the array. It is important to note that the index values in the square are calculated from 0. 、

4. Statement of structure

  first way of declaring: standard, formal  struct   person{ int   age;  float   height;}; The second way of declaring is that the structure of anonymity is generally used only once  struct   { int   age;  float   height;} P2; the third typedef  struct   emp{ int   Age;} Employee; fourth typedef  struct   { Span style= "color: #0000ff;" >int   Age;} Employee;  

5. Pointers

(1) If a variable is declared with the * sign in front, it indicates that this is a pointer-type variable. In other words, the variable stores an address, and * is the content operator, which means to take the content stored in the memory address.

(2) The pointer can be not only the address of a variable, but also an array, an array element, a function address. A pointer can be used as a formal parameter to get more than one return value in the function's call procedure (unlike return (Z), only a return value can be obtained.

(3) The pointer is a double-edged sword, many actions can be expressed naturally by the pointer, but incorrect or excessive use of the pointer will bring a lot of potential errors to the program.

(4) Basic application of pointers:

1), ++,--,+,-

int arr[]={1,2,3};     int *p=arr;     int *p2=&arr[1]; p2--;     printf ("%d\n", *P2);

This will output 1;

2), as a function parameter

int Jiaohuan (int *a,int *b) {    int temp=*A;     *a=*b;     *b=temp;}

3), as a function return value

Char* getmemory ()             {                      charnewchar[ + ];                       return p;             

4), void*

void literal means "no type", void * is "untyped pointer", void * can point to any type of data. This does not mean, however, that void * can also be assigned to other types of pointers without forcing the type to convert. Because "untyped" can contain "there is a type," and "there is a type" cannot tolerate "untyped". Hehe, this truth is quite simple, we can say "men and women are people", but can not say "man is a Man" or "man is a woman."

5), pointer array: int *P[3];

First it is an array, the elements of the array are pointers, and the number of bytes in the array is determined by the array itself. It is the abbreviation for "array of stored pointers"

#include <stdio.h>//output A string with a pointer arrayintMain () {Char*p[5]={"qwe","ASD","RTT","FGH","vbc"}; inti;  for(i =0; I <5; i++) {printf ("%s\n", P[i]); }}

6), pointer: type character * * variable name (for example: **p)

int a=5;     int *p;     int **pp; // *pp is a pointer    to int* type data p=&A;    PP=&p; // assign P's address to PP    **pp=a;

7), Function pointers

       

 int (*f) (int/** /

#include <stdio.h>intAddintAintb) {    returnA +b;}intMain () {intA=3; intb=3; int(*p) (int,int); P=add; intresult= (*p)    (A, B); printf ("%d\n", result);}

8), the role of the pointer:

Pointers can be used to effectively represent complex data structures, and can be used for function parameter passing and for more flexible use of functions. The design of C language has the characteristics of flexibility, practicality and efficiency. Pointers are not only the soul of C language, the use of the good is more than a multiplier, so that you write a more concise program!

6. Common Debug Commands (LLDB)

File Filename
B (Breakpoint) Breakpoint
BR List All the Breakpoints
BR del Delete Breakpoint
L Display code
N:next Next
S:sept Single Step operation
Continue Go on
Finish End
Print Print a value for a variable
Frame variable Frame variable
Diplay The value of the variable is displayed each time it is run to a breakpoint to observe the change of the variable
Expr Change the value of a function
Q Exit run

7. Dynamic memory

(1) malloc

(2) Calloc

(3) ReAlloc

(4) Free

iOS interest Class (ii)

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.