Question

Computer Science Midterm Exam Review Questions 11. What is a pointer? 12. Are pointers and array...

Computer Science Midterm Exam Review Questions

11. What is a pointer?

12. Are pointers and array names the same thing? How are they alike? How do they differ?

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

11

Ans:

Pointer: Pointer is variable which stores the address of a variable .

Ex:

int num=10;

int *ptr=&num ; // it means here ptr is a pointer variable and we are storing address of num in this pointer variable

Ex:

int a[10];

int *ptr=a; // here ptr is a pointer variable and we are storing the base address of array in this array variable.

12

Ans:

Yes we can assume that both pointers and array names are same thing.

But sometimes we use array names and some times we use pointer to that array

Ex:

If we want to interate through the array in the main function then

for(i=0;i<n;i++)

printf("%d",a[i]); // here this a[i] prints all elements of array;

If we want to pass the array to some function and we have to print array values then we use pointers

void printing(int *arr,int arr_len)

int i=0;

for(i=0;i<arr_len;i++)

printf("%d",(arr+i)*); // here it will print array values

int main()
int a[10],n=10;

printing(a,n);

Add a comment
Know the answer?
Add Answer to:
Computer Science Midterm Exam Review Questions 11. What is a pointer? 12. Are pointers and array...
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