Getting Started with C programming-pointers (bottom)

Source: Internet
Author: User

Overloading of functions:

# include <stdio.h>void swap (void) {printf ("Hehe! \ n "); return;} void swap (int i, int j) {printf ("Haha! \ n "); return;} int main (void) {swap (), swap (1, 2),//function with the same name, different number of parameters, and not the same function. int i = 3;printf ("i =%d\n", i);//free (); The free function frees the variable to occupy the memory of printf ("I =%d\n", i); return 0;}


The modulated function modifies the value of the variable in the main function:

# include <stdio.h>void change (int * p) {*p = 10;//equivalent to: i = 10;return;} int main (void) {int i = 3;printf ("before modification: i =%d\n", i); change (&i);//If you want to modify the function, you must send the address. printf ("Modified: i =%d\n", i); return 0;}

Empty pointer null:

# include <stdio.h>int main (void) {int * p;//printf ("%d", *p);//read a piece of space without access and cause the program to crash. int * Q;q = null;printf ("%d", *q); The memory space pointed to by the null pointer is not readable or writable and is directly faulted. return 0;}


Operation of pointer variables:

# include <stdio.h>int main (void) {int i = 3;int j = 5;int A[50];int * p = &i;int * q = &j;q-p;//not in the same storage space Two variables I, J address subtraction meaningless. p = &a[1];q = &a[44];p rintf ("%d\n", q-p); That is, the hexadecimal number is subtracted and then output in decimal. return 0;}

The byte that the pointer variable occupies:

# include <stdio.h>int main (void) {int i = 3;int Len;len = sizeof (char *);//sizeof function, the number of bytes that the return data type occupies. printf ("%d\n", Len); return 0;} /* After many experiments, a pointer variable, regardless of the type of pointer variable, is 4 bytes (32-bit machine). */



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Getting Started with C programming-pointers (bottom)

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.