Knowee
Questions
Features
Study Tools

For the following statements will arr[3] and ptr[3] fetch the same character?char arr[] = "all the best";char *ptr = " all the best  ";

Question

For the following statements will arr[3] and ptr[3] fetch the same character?

char arr[] = "all the best";
char *ptr = " all the best ";
🧐 Not the exact question you are looking for?Go ask a question

Solution

No, arr[3] and ptr[3] will not fetch the same character.

Here's why:

In the array arr[], the indexing starts from 0. So, arr[3] will fetch the 4th character of the string "all the best", which is a space (' ').

On the other hand, in the pointer *ptr, ptr[3] will fetch the 4th character of the string " all the best ", which is 'l'.

So, arr[3] is a space (' ') and ptr[3] is 'l'. They are not the same.

This problem has been solved

Similar Questions

What is the output of the following C code?char *ptr;char mystring[] = "abcdefg";ptr = myString;ptr += 5;

Find output of the below program:int main(){  char str[]={'e','a','r','t','h'};  printf("%s", str);  return 0;}

Which one of the following is a valid statement? char[] c = new char();char[] c = new char[5]; char[] c = new char(4); char[] c = new char[];

1.What is the output of the following code?char str[] = "hello";printf("%c\n", str[1]);

What is the default return-type of getchar()?a.charb.Intc.char *d.reading character doesn’t require a return-type

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.