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

void main() { int i=i++,j=j++,k=k++; printf(“%d%d%d”,i,j,k); }

1 Answers  


main() { extern int i; i=20; printf("%d",sizeof(i)); }

2 Answers  


main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }

1 Answers  


void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }

2 Answers  


What is the output for the following program main() { int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }

1 Answers  






main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above

3 Answers   HCL,


main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }

2 Answers   Adobe, CSC,


main() { printf("%d", out); } int out=100;

3 Answers  


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

1 Answers  


what is variable length argument list?

2 Answers  


int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }

3 Answers   Cisco, HCL,


How will you print % character? a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”)

4 Answers   HCL,


Categories