C Language Doubt Point

Source: Internet
Author: User

Const

The compiler typically does not allocate memory for normal const, but instead saves them in the symbol table.

This makes it a constant during compilation, with no storage and read operations, making it highly efficient

const INT * Const P4 = &a;

const INT * P4 = &a;

int * Const P4 = &a;

Memory skills look at the position of *

If the const on the left side of the * indicates that the value cannot be changed, but pointing can change

If const on the right side of the * indicates that the point cannot be changed, but the value can be changed

If on * But both sides there is a const identity point and the value cannot be changed

5) malloc function:

int main (int argc, const char * argv[]) {

The first address of the newly requested memory space is stored in P

If you do not assign a value to a malloc application, the amount of garbage stored is

int *p = (int *) malloc (4 * sizeof (int));//16 bytes

Calloc: Allocating memory space for the specified number of blocks and lengths

Format: calloc (number of blocks, length)

Allocated 4 pieces of memory with 4 bytes each

Their addresses are also contiguous and can be automatically initialized to 0.

int *P1 = (int *) calloc (4, sizeof (int));

Relloc can extend the size of existing memory space

return new memory space address

p = realloc (p, + * sizeof (int));

Using a function to initialize the memset, the intermediate is the ASIC code;

memset (P, ' A ', 16);

if (P! = NULL) {

*p = 10;

* (p + 1) = 100;

* (p + 2) = 1000;

}else{

printf ("Failed to request memory space!") ");

}

printf ("%p%p%p", *p, * (P + 1), * (P + 2));

return 0;

}

C Language Doubt Point

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.