what will be the result of the following program ?
char *gxxx()
{
static char xxx[1024];
return xxx;
}

main()
{
char *g="string";
strcpy(gxxx(),g);
g = gxxx();
strcpy(g,"oldstring");
printf("The string is :
%s",gxxx());
}
a) The string is : string
b) The string is :Oldstring
c) Run time error/Core dump
d) Syntax error during compilation
e) None of these

Answers were Sorted based on User's Feedback



what will be the result of the following program ? char *gxxx() ..

Answer / jaya prakash

b) The String is :OldString

Because ,for Static var memory is only one time created.
Eventhough the fn is multiple times called,
so
consider addr of xxx is 4444,
first strcpy copy the string "string" to addr 4444,
then g=4444;
then oldstring overwrites to location 4444.

Is This Answer Correct ?    8 Yes 0 No

what will be the result of the following program ? char *gxxx() ..

Answer / abhiraj

oldstring

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More C Interview Questions

write a program to copy a string without using a string?

2 Answers  


What the advantages of using Unions?

0 Answers   TISL,


write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.

0 Answers  


State the difference between realloc and free.

0 Answers   Aricent,


write a function which accept two numbers from main() and interchange them using pointers?

3 Answers  






Tell me with an example the self-referential structure?

0 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers   Mind Tree,


the number 138 is called well ordered number because the three digits in the number (1,3,8) increase from left to right (1<3<8). the number 365 is not well ordered coz 6 is larger than 5. write a program that wull find and display all possible three digit well ordered numbers. sample: 123,124,125,126,127,128,129,134 ,135,136,137,138,139,145,146,147 148 149,156.......789

5 Answers  


4. main() { int c=- -2; printf("c=%d",c); }

0 Answers  


Write a program that will read the input of any number of digits n in a row of shafh showing the breakdown of the printing and printing figures by the recursive function.

0 Answers  


In C program, at end of the program we will give as "return 0" and "return 1", what they indicate? Is it mandatory to specify them?

5 Answers  


write a program to count the no of repaeted words in a line?

1 Answers  


Categories