Difference between Pointer and Array in C

Question: Are Pointers and Arrays Same in C Answer: Let’s, first, see their declarations, char name[20]; /* ‘name[20]’ a character array declared */ char alphabet; char *cp = &alphabet; /* ‘cp’ pointer-to-character points to alphabet */ and now analyse them. When compiler comes across the statement char name[20]; it allocates block of 20 bytes of … Read more

advertisement

Difference between array[i] and i[array] Expressions

Question: Are Expressions arrays[i] and i[arrays] same? Answer: We know that we can use pointer and indirection to access an array. Let’s try to rewrite the exp. arrays[i]; using pointer as: *(arrays + i); which, of course, we can write as: *(i + arrays); /* addition is ‘commutative’ */ which we rewrite in subscript form … Read more

advertisement

Array in C with Examples

This Tutorial explains an Array in C with Example(s). What is an Array in C? An array can be thought of as an arrangement of a specified number of elements of the same kind stored in contiguous memory locations and this arrangement is given a name. Syntax of Array Declaration: type name[size]; Here, Type is … Read more

advertisement

Are Pointer References More Efficient than Array Indexes in C

Question: Is Pointer more Efficient than using Subscript to Access an Array in C Programming? Answer: Let’s first consider examples below, int stud_passed[5] = {234, 11, 456, 99, 887}; int *pi; int i; Now, we try accessing the array ‘stud_passed[]’ using subscript and ptr-to-int, ‘pi’ for (i = 0; i < 5; i++) stud_passed[i]; /* … Read more

advertisement

Can we Use a Pointer for Subscript to Access an Array in C?

Question: Can we Use Pointer for Subscript to Access an Array in C Programming? Answer: Subscript operator ‘[]’ have higher precedence than indirection operator ‘*’, but in fact, both are same. Let’s see an example, int max[5] = {1,2,3,4,5}; /* max[5] is an array of 5 integers */ Well! In order to access elements of … Read more

advertisement

Array Subscript in C with Examples

This C Tutorial Explains Array Subscript in C Language with Example(s). An array subscript in C is an integer type constant or variable name with a value ranging from 0 to SIZE 1. (Where size is the total no of elements in the array). Let’s start with what we already know by considering the declaration … Read more

advertisement

One Dimensional Array in C with Examples

This C Tutorial Explains One Dimensional Array in C and its initialization with Example(s). What is One Dimensional Array in C? An array with just one dimension is called one-dimensional array. Dimension of an array is specified by a pair of square brackets called subscript immediately after the name of array. Syntax of One Dimensional … Read more

advertisement

Difference between Array and Variable in C

Question: What is the Difference Between Declaration of an Array and a variable in C? Answer: Let’s try to understand following declarations, int main(void) { int x; /* x is declared as integer */ char initial; /* initial is a character */ int num[10]; /* num is an array of 10 integers */ char msg[10]; … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.