C Basic knowledge "pointers"

Source: Internet
Author: User

July 11, 2017 18:33:41
The C-pointer should look at address: http://www.runoob.com/cprogramming/c-pointers.html
1. Learning the C language pointer is simple and fun. With pointers, you can simplify the execution of some C programming tasks, and there are tasks such as dynamic memory allocations that cannot be performed without pointers. Therefore, to be a good C programmer, learning pointers is very necessary.
As you know, each variable has a memory location, and each memory location defines an address that can be accessed using the hyphen (&) operator, which represents an address in memory. Take a look at the following example, which will output the defined variable address:
Instance
#include <stdio.h>

int main ()
{
int var1;
Char var2[10];

printf ("Address of the VAR1 variable:%p\n", &var1);
printf ("Address of the VAR2 variable:%p\n", &var2);

return 0;
}
2. What is a pointer?
A pointer is a variable whose value is the address of another variable, that is, the direct address of the memory location. Just like any other variable or constant, you must declare it before using the pointer to store other variable addresses. The general form of a pointer variable declaration is:
Type *var-name;
Here, type is the base type of the pointer, it must be a valid C data type, and Var-name is the name of the pointer variable. The asterisk * used to declare the pointer is the same as the asterisk used in the multiplication. However, in this statement, the asterisk is used to specify that a variable is a pointer. The following is a valid pointer declaration:
int *ip; /* A pointer to an integral type */
Double *DP; /* A double type of pointer */
float *FP; /* A floating-point pointer */
Char *ch; /* A pointer to a character type */
The actual data type of the value of all pointers, whether integer, float, character, or other data type, is the same as a long hexadecimal number representing the memory address. The only difference between pointers to different data types is that the data type of the variable or constant that the pointer points to is different.
3.

C Basic knowledge "pointers"

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.