devxlogo

Pointers and Arrays

C++ never passes arrays to a function. Instead, the argument is implicitly converted to a pointer that contains the address of the first array element. For example:

 void f(char s[]);int main(){ char buff[10]; f(buff); // buff is quietly converted to '&buff[0]'}


Because of this implicit conversion, you may access elements of an array in two forms:

 *(s+n) = 'a'; // pointer notations[n] = 'a' // array notation


In fact, even if s is a real pointer, you may use the [] notation:

 char *s=new char[10];s[0]='0';

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.