Question

a. In your own words, give a definition of a "pointer" in C++. b. In your...

a. In your own words, give a definition of a "pointer" in C++.

b. In your own words, explain the array/pointer duality law relationship.

c. In your own words, explain the two mechanisms for manipulating strings in C++.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Pointer:

In Programming Language C++, a pointer is a special type of variable which is used to store the address of another variable which has the same data type as the pointer data type.

Array/pointer duality law relationship:

An array and pointer have a complicated relationship because the array is treated as a pointer by the compiler and the name of the array work as a constant pointer. When we pass an array to the function as a parameter then the base address of the array is passed and because of this, the original array element can be changed by that function.

The name of the array is the base address or pointer to the first element of the array. By using the base address, we can access all other elements of the array as well.

Two mechanisms for manipulating strings in C++:

We can declare an array in two ways as given below:

char str1[] = "hello";
string str2 = "hello";

The first declaration is an array of characters and the second declaration is using the library functionality.

First mechanisms:

We can manipulate an array by using the index as given below:

str1[0] is representing the first character.

str1[1] is representing the second character.

str1[2] is representing the third character.

We can use loops to manipulate any operation like to find the size of the string, to copy the string, etc

Second mechanisms:

We can manipulate an array by using the string class and its associated method as given below:

The function strlen() is used to find the length of the string.

The function strcat() is used to concatenate the one string at the end of the other string.

The function strcpy() is used to copy one string into another string.

Add a comment
Know the answer?
Add Answer to:
a. In your own words, give a definition of a "pointer" in C++. b. In your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT