"Take you to learn C take you to fly"---pointer and array

Source: Internet
Author: User

1. Arrays are never pointers

2. When you receive data using the SCANF function, you can replace the address of the variable with a pointer

int A; int *p = &a;scanf ("%d", &a); // available scanf ("%d", p); alternative

3. Receive string with%s

Char str[];scanf ("%s", str);

4. The array name is the address of the first element of the array, pointing to the array with a pointer

Char " FISHC " ; char *p = A;

5. (p+1) refers to the next element of the array, rather than simply adding 1 to the address

printf ("*p =%c,* (p+1) =%c\n", *p,* (p+1)); // Remember to tie the brackets

You can also access the array directly using the

printf ("a =%c,a+1 =%c\n", *a,* (A +1));

6. Character pointer variables

#include <stdio.h>#include<string.h>intMain () {Char*str ="I love fishc.com! "; inti,length; Length=strlen (str);  for(i =0; I <length; i++) {printf ("%c", Str[i]); } printf ("\ n"); return 0;}

"Take you to learn C take you to fly"---pointer and array

Related Article

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.