main()

{

int i, n;

char *x = “girl”;

n = strlen(x);

*x = x[n];

for(i=0; i<n; ++i)

{

printf(“%s\n”,x);

x++;

}

}

Answers were Sorted based on User's Feedback



main() { int i, n; char *x = “girl”; n = strlen(x); ..

Answer / susie

Answer :

(blank space)

irl

rl

l

Explanation:

Here a string (a pointer to char) is initialized with a
value “girl”. The strlen function returns the length of the
string, thus n has a value 4. The next statement assigns
value at the nth location (‘\0’) to the first location. Now
the string becomes “\0irl” . Now the printf statement prints
the string after each iteration it increments it starting
position. Loop starts from 0 to 4. The first time x[0] =
‘\0’ hence it prints nothing and pointer value is
incremented. The second time it prints from x[1] i.e “irl”
and the third time it prints “rl” and the last time it
prints “l” and the loop terminates.

Is This Answer Correct ?    8 Yes 3 No

main() { int i, n; char *x = “girl”; n = strlen(x); ..

Answer / arhant jain

Segmentation fault

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Code Interview Questions

main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }

1 Answers  


void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

2 Answers  


Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  


main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }

1 Answers  


what is oop?

3 Answers  






main() { char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute?

2 Answers  


What is your nationality?

1 Answers   GoDB Tech,


#include<stdio.h> int main() { int a=3,post,pre; post= a++ * a++ * a++; a=3; pre= ++a * ++a * ++a; printf("post=%d pre=%d",post,pre); return 0; }

3 Answers  


void main() { int c; c=printf("Hello world"); printf("\n%d",c); }

2 Answers  


int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

2 Answers  


void main() { int i=10, j=2; int *ip= &i, *jp = &j; int k = *ip/*jp; printf(“%d”,k); }

1 Answers  


Program to Delete an element from a doubly linked list.

4 Answers   College School Exams Tests, Infosys,


Categories