Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,621 questions

10,674 answers

573 users

What is the difference between pointer to integer and pointer to an array of N integers in C

1 Answer

0 votes
#include <stdio.h>     

#define N 5

int main(void)
{
    int *p_int; // pointer to integer
	int (*p_arr)[N]; // pointer to an array of 5 integers
	int arr[N] = {3, 8, 6, 1, 9};
    
	p_int = arr; // pointer to arr[0]
	p_arr = &arr; // pointer to the whole array
    
    printf("p_int = %p, p_arr = %p\n", p_int, p_arr);
    printf("*p_int = %d, *p_arr[0] = %d\n", *p_int, *p_arr[0]);
    printf("*(p_int + 1) = %d, *(p_arr[0] + 1) = %d\n", *(p_int + 1), *(p_arr[0] + 1));
    
	p_int++;
	p_arr++;
	printf("p_int = %p, p_arr = %p\n", p_int, p_arr);
    printf("*p_int = %d, *p_arr[0] = %d\n", *p_int, *p_arr[0]);
    
    return 0;
}

/*
run:

p_int = 000000000022FE20, p_arr = 000000000022FE20
*p_int = 3, *p_arr[0] = 3
*(p_int + 1) = 8, *(p_arr[0] + 1) = 8
p_int = 000000000022FE24, p_arr = 000000000022FE34
*p_int = 8, *p_arr[0] = 0

*/

 




answered May 14 by avibootz
...