edited by
1,102 views

3 Answers

Best answer
9 9 votes

Let's suppose the starting address of the array is $200$. Then array $q$ is stored like $\Rightarrow$

Now, $*p = q+ 4$ means p stores the address $204$, Now strcpy() function writes the string $q$ staring from address $204$ with string best. and the string q becomes $\Rightarrow$

printf("%s",q); prints string $q$ till it sees NULL character.So, madebest is printed here.

edited by
2 2 votes
p will contain the string from 5th character(start from 0th position in q) so p contains "easy2016"..  now strcpy will copy "best" to p.. and adds a null character at the end.. since % s prints till the null character it will print "madebest"..
1 1 vote
char * strcpy ( char * dest, const char * src );

Copies the string pointed by src into the array pointed by dest, including the terminating null character.

#include <stdio.h>
#include <string.h>
int main() {
    char q[] = "madeeasy2016";
    char *p = q+4;


/* String literal "madeeasy2016" is lying somewhere in the read-only area of memory. 
q is pointing to the address of 'm' and now p is pointing to the address of second 'e'
*/
    printf("%s\n",p);
    /* easy2016 will be printed */
    
    strcpy(p,"best");
    printf("%s\n",q);
    return 0;
}


 

So, madebest will be printed.

edited by
Position:
Show:

Related questions

2 2 votes
1 1 answer
2.1k
2.1k views
Ram Swaroop asked Jan 29, 2019
2,132 views
Consider the following C code:include <stdio.h>int fun(){static int num=25;return num ;}int main(){for(fun( ); fun();fun())printf("%d", fun( ));return O;}The sum of the v...
2 2 votes
0 0 answers
1.3k
1.3k views
srestha asked Jan 28, 2019
1,318 views
void foo(int n) { for(i1=1;i1<=n;i1++) { for(i2=1;i2<=i1;i2++) { ....... { for(i6=1;i6<=i5;i6++) { count++; } } } } }Count initially 0.What is value returned by foo(8)?
0 0 votes
1 1 answer
859
859 views
Markzuck asked Jan 10, 2019
859 views
Please explained detialed execution of this code, I am not getting how int stored in char, like we can interchange using ASCII but still cant store right?
3 3 votes
2 answers 2 answers
989
989 views
Shamim Ahmed asked Dec 11, 2018
989 views
char *a = “MADEEASY”;char *b = “GATECSIT2019”;char *r = a;char *s = b;printf(“%d”, (int) strlen (b+3[r] – 1[s]));return 0; Whats the output? Answer given 8