On the study of C language, I think there are some misunderstandings in the pointer and array. In the free time to write a little personal experience, I feel that writing is not very good, just a small personal experience, write bad, but also please master forgive me, pointing under the misunderstanding, contact [email protected],
Also hope that you master enlighten.
========================================
All variables in the C language are memory, and defining variables is requesting memory
======================================
1. String
======================================
1. The string is in memory in the form of a character array, ending with '/', Length: number of characters +1;
String in the operation: the first address assigned to the address, take the string is not required * (for example: Char *p= "gght"; printf ("%s", p);), but need to add * when taking characters;
String operation Loop End flag: Judge p[i]== ' + '; or strlen (p);
sizeof (p)/sizeof (p[0])----> capacity
sizeof calculates the total size of the entire array
Strlen calculates the size of the string itself without '
=======================================
2. Arrays and pointers
=======================================
1. Pointers and other types of swaps: both address
A.int A; int *p; p=&a;
B.int A[3]; int (*p) [3]; p=&a;
C.int *a[3]; int * (*A) [3]; p=&a;
2. Array operations are treated as pointers, first addresses and operations
3. Array length: char a[]; sizeof (a)/siaeof (A[0])-1;
4. Array and pointer operations:
Such as:
int a[3]; | int a[3];
int *p; | int *p[3];
P=a; | p=&a;
a[i]=* (p+i); |
Pointer and array operations: divided into two parts: the 2nd part of the same is taken: the first address
The 2nd part is different, take: &: Entire address
sizeof () of the pointer = 4; As long as the pointer is the constant theorem
<5>. Flexible use of arrays:
char * a[]: Divided into two parts: 1:a[]; 2:char*;
Char a[]: divided into two parts: 1:a[]; 2:char;
=========================================
3. Complex statement Reading
=========================================
How to read: Find the first non-key character and peel the Onion as he centers
such as: void (* Signed (Signed, Void (*p) int)) int
typedef tmp VOID (*) int
TMP signed (signed, TMP p)
=========================================
4. Data type
=========================================
1. Redefine:
typedef long int32_t; Define int32_t as Long 4 bytes
typedef short INT32_4 defines int32_t as short 4 bytes
int 4 bytes, char 1 bytes, short 2 bytes, long 4 bytes;
Double:%lf float:%f;
2. Force type conversions:
such as: int p;
(char) p; int--->char
==========================================
5. Memory
==========================================
OS------> operating system
|
|
Stack------> Local variables, formal parameters (after the function runs, memory is released)
|
|
Heap------>malloc (), Calloc (), realloc () allocate memory, must be in conjunction with free ()
|
|
Data segment----> global variables, static variables (memory is not freed after function run ends)
=======================================
6. Commissioning
=======================================
#ifdef x;
printf ("..", x);
#enif
Debug partial compile time: gcc--. c-o. -DX only works.
----------------------------------> completed on: March 10, 2015
This article is from the "C Language misunderstanding" blog, please be sure to keep this source http://10443940.blog.51cto.com/10433940/1663513
C language Misunderstanding