I am learning about pointers and how they work in general. I have found some example code online: https://overiq.com/c-programming-101/pointers-and-2-d-arrays/
#include<stdio.h>
int main()
{
int *p; // pointer to int
int (*parr)[5]; // pointer to an array of 5 integers
int my_arr[5]; // an array of 5 integers
p = my_arr;
parr = my_arr;
printf("Address of p = %u\n", p );
printf("Address of parr = %u\n", parr );
p++;
parr++;
printf("\nAfter incrementing p and parr by 1 \n\n");
printf("Address of p = %u\n", p );
printf("Address of parr = %u\n", parr );
printf("Address of parr = %u\n", *parr );
// signal to operating system program ran fine
return 0;
}
However, I am having an error when debugging this code:
Severity Code Description Project File Line Suppression State
Error C2440 '=': cannot convert from 'int [5]' to 'int (*)[5]' First_project_vs C:\Users\Lukas\Desktop\VS_projects\First_project_vs\First_project_vs\First_project_vs.cpp 16
Perhaps someone can help me understand what is the issue here? Is the example provided code wrong?
Also, I am learning from the following video: https://www.youtube.com/watch?v=zuegQmMdy8M&ab_channel=freeCodeCamp.org
If you go to 1:48:52, You will see, that he is suggesting a similar method of declaring a pointer which I am also having issues compiling.
Can someone shed some light to me about what is wrong here? Appreciate any help