dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Aug 1, 2001

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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 notation
s[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';
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date