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(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }

2 Answers  


How to read a directory in a C program?

4 Answers  


&#8206;#define good bad main() { int good=1; int bad=0; printf ("good is:%d",good); }

2 Answers  


write a program to Insert in a sorted list

4 Answers   Microsoft,


void main() { while(1){ if(printf("%d",printf("%d"))) break; else continue; } }

1 Answers  






#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }

1 Answers  


C statement to copy a string without using loop and library function..

2 Answers   Persistent, TCS,


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.

6 Answers   Fusion Systems GmbH,


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

4 Answers   Corporate Society, HCL,


#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

1 Answers  


What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }

1 Answers  


how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

0 Answers  


Categories