C language has an integer array a with 10 elements. All elements in the array must be output.

Source: Internet
Author: User

C language has an integer array a with 10 elements. All elements in the array must be output.

 

There is an integer array a with 10 elements. All elements in the array must be output.

 

Solution: There are three methods to reference the values of each element in the array: 1. subscript method, such as a [3]; 2. calculate the address of the array element using the array name to find the element value.

3. Use Pointer variables to point to array elements.

 

// Use Pointer variables to point to array elements # include
 
  
Int main () {int a [10]; int I; int * p; printf ("Enter 10 integers \ n"); for (I = 0; I <10; I ++) scanf ("% d", & a [I]); for (p = a; p <(a + 10); p ++) printf ("% 2d", * p); printf ("% \ n"); return 0;} // calculate the array element address using the array name # include
  
   
Int main () {int a [10]; int I; printf ("Enter 10 integers \ n"); for (I = 0; I <10; I ++) scanf ("% d", & a [I]); for (I = 0; I <10; I ++) printf ("% 2d ", * (a + I); printf ("% \ n"); return 0;} // subscript method # include
   
    
Int main () {int a [10]; int I; printf ("Enter 10 integers \ n"); for (I = 0; I <10; I ++) scanf ("% d", & a [I]); for (I = 0; I <10; I ++) printf ("% 2d ", a [I]); printf ("% \ n"); return 0 ;}
   
  
 

 

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.