Character Array MCQ 6 : Pointer and String [*(arr+i) = 65+i; ]




Character Array MCQ 6 : Pointer and String


What is the Output of the Following Program ?

#include< stdio.h>
int main()
{
char arr[20];
int i;
for(i=0;i<10;i++)
     *(arr+i) = 65+i;
*(arr + i) = '\0';

printf("%s",arr);
return(0);
}

Options :

  1. ABCDEFGHIJ
  2. AAAAAAAAAA
  3. JJJJJJJJJJ
  4. None Of These

Output:


Switch to String MCQ Home : Click Here


How and Why ?

  • (arr + i) gives Address of the i’th element from the Base Address.
  • *(arr + i) gives “Value at This Address”.
  • Each Time we are Assigning 65 + i .
  • In First Iteration i = 0 and 65 is Assigned i.e ‘A’ [ASCII Value of ‘A’ is 65 ].