Discussion :: Strings - Yes / No Questions (Q.No.2)
For the following statements will arr and ptr fetch the same character?
Answer: Option A
Yes, both the statements prints the same character 'i'.
|Vikas Kumar said: (Jun 17, 2011)|
|I think answer is wrong... because ptr will print the addres of the 'i'..
Reply me soon..
|Sundar said: (Jun 17, 2011)|
|The given answer is correct. I have tested the following code:
char arr = "IndiaBIX";
char *ptr = "IndiaBIX";
printf("\n arr = %c", arr);
printf("\n ptr = %c", ptr);
arr = i
ptr = i
|Rupinder said: (Nov 25, 2011)|
|Here are two different techniques to point to the any of the array elements.
#2: Pointer arithmetic(ptr==>*(ptr+3))
Read the pointer arithmetic concept, you'll be able sort this out by your own.
|Karthika said: (Jun 22, 2016)|
|But I have a doubt *ptr gives I as output then it means it is not a pointer but that is not the case with C. So please clear my doubt.|
|Waghmare N.I. said: (Aug 1, 2016)|
|Yes, the answer is written after executing code but the pointer is used to store the address of a variable in the memory.
And here pointer have size 3 and array have 3 character string. But the pointer addresses.
I am confused about the problem please solve this confusion.
|Pranali said: (Apr 1, 2017)|
In arr and ptr we are storing same value/string. And we are accessing 3rd element from both the array and pointer. so it will print 'i'.
As we access each and every element from array by saying, arr,arr, etc.
same like that pointer works as ptr,ptr, etc.
Understand the concept of pointer arithmetic, then you will get it.
Post your comments here:
Email : (optional)
» Your comments will be displayed only after manual approval.