C language pointers

Source: Internet
Author: User



#include  <stdio.h>int main () { int i = 10;//an int variable, named i int *p;/ /defines a pointer variable  //p = 10;//error that points to an integer, it is not possible to assign an integer directly to the pointer variable. Each variable in the &NBSP;//C language has its own memory address. The & symbol is the variable address operator.  &i;//takes the address of the variable I.  p = &i;//points the pointer variable p to the address of I.  *p = 100;// Assign the value of the memory area that P points to 100; printf ("i = %d\n",  i);  int *p1 = &i; int  a = *p;//* is the value of the pointer pointing to memory in C language  //int b = null; int *p2 =  null; int *p3;//defines a pointer variable that points to int, without assigning an initial value, which is a wild pointer to what memory address is not known. The  //of the wild pointer is only the program itself, does not affect the operating system.  //If you are doing a driver or kernel code, then it can be fatal and the operating system crashes. The  //*p3 = 10;//field pointer is also called a dangling pointer, and cannot assign a value to the area of memory that the wild pointer points to.  char c =  ' a ';  //p3 = &c;//in the C language, when the pointer is assigned to a value, be sure to type compatible  unsigned  int ui = 10; p3 = &ui;  void *p4;//defines an untyped pointer.  p4 = &i;//can assign any type of address to void * //p1 = p4;//(You can assign void * to any type of pointer variable in the C language). But the C + + statement is illegal  printf ("*p4 = %d\n",  * (int * P4);  //P4 this value into a pointer, and then see what is inside the pointer  printf ("*p = %d\n", &NBSP;*P3);  printf ("a = % D\n ",  a);  getchar ();  return 0;}


This article from "Soul Bucket Luo" blog, declined reprint!

C language 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.