devxlogo

Accessing the Address of a String Element

Accessing the Address of a String Element

Question:
In the following code, how do I get the address of the first character of str in the function discard?

discard(string *name){ //..}int main(){   string str;  cin >> str;  discard(str);  return(0);}

Answer:
It’s simple: &str[0] returns the address of the first character of the string object.

devxblackblue

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.

About Our Journalist