456 views

1 Answer

Best answer
3 votes
3 votes
r is a character pointer. r[6] = 'M' and r[3] = 'G'.

In C language, alphabet letters must have consecutive integer values.So, r[6] - r[3] = number of letters between 'G' and 'M' = 6.

Now, r + 6 = value in r + 6 * (sizeof(char))

= r + 6.

When %s is used in printf, all characters are printed from the passed address till "\0". So, when r+6 is passed, all characters from the location r+6 are printed till "\0". So,we get M1234 as output.

PS: In C language "\0" is automatically added at end to all string literals like "PROGRAM1234".
selected by

Related questions

0 votes
0 votes
1 answer
3
Rohit Gupta 8 asked Nov 8, 2017
7,041 views
Let A be a square matrix of size n x n. Consider the following program. What is the expected output?C = 100 for(i=0; i<n; i++) for (j=0; j<n; j++) { Temp = A[i][j] + C A[...
0 votes
0 votes
2 answers
4
ajit asked Sep 2, 2015
2,063 views
#include<stdio.h #include<math.h int main() { double pi=3.1415926535; int a=1; int i; for(i=0;i<3;i++) if(a=cos(pi*i/2)) printf("%d",1); else printf("%d",0); }0 0 00 1 01...