C language Pen question selection 2---int a[10]; q Which of the following can not represent a[1] addresses?

Source: Internet
Author: User

Question: int a[10]; q Which of the following can not represent a[1] addresses?

A, a+sizeof (int)

B, &a[0] + 1

C, (int*) &a+1

D, (int*) ((char*) &a+sizeof (int))


#include <stdio.h>int main () {int a[10] = {1,2,3,4,5,6,7,8,9,0};p rintf ("******* output Address *******\n");p rintf ("a[0]  =%d\n ", a);p rintf (" a+sizeof (int) =%d\n ", a+sizeof (int));  A+1 for address plus 4, here is equivalent to add the address of printf ("&a[0" + 1 =%d\n ", &a[0] + 1);  This plus 1 is also the address plus 4 printf ("(int*) &a+1 =%d\n", (int*) &a+1); Add 1 is also the address plus 5 printf ("(int*) ((char*) &a+sizeof (int)) =%d\n", (int*) ((char*) &a+sizeof (int)));// This first turns the address into a char-type pointer, and then +4 is added by the char type length, and finally to the integer printf ("\ n"); printf ("******* output Value *********\n");p rintf ("a[0] =%d\n", *a);p rintf ("a+sizeof (int) = %d\n ", * (a+sizeof (int)));p rintf (" &a[0] + 1 =%d\n ", * (&a[0] + 1)); printf ("(int*) &a+1 =%d\n", * ((int*) &a+1));p rintf ("(int*) ((char*) &a+sizeof (int)) =%d\n", * (( int*) ((char*) &a+sizeof (int))); return 0;}

Output:


Results:

The answer is a.

C language Pen question selection 2---int a[10]; q Which of the following can not represent a[1] addresses?

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.