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 for fibonaci series by using while loop in c?

2 Answers  


what is output? main() { #define SQR(x) x++ * ++x int i = 3; printf(" %d %d ",SQR(i),i * SQR(i)); } a)9 27 b)35 60 c)20 60 d)15 175

5 Answers   Wipro,


Explain the concept and use of type void.

0 Answers  


Can a pointer point to null?

0 Answers  


How to receive strings with spaces in scanf()

7 Answers  






write the program for maximum of the following numbers? 122,198,290,71,143,325,98

5 Answers  


Explain what is a const pointer?

0 Answers  


What is bubble sort in c?

0 Answers  


why programs in c are running with out #include<stdio.h>? some warnings are display in terminal but we execute the program we get answer why? eg: main() { printf("hello world "); }

0 Answers  


Write a program to print distinct words in an input along with their count in input in decreasing order of their count

0 Answers  


count the numbers between 100 and 300, that star with 2 and ends with 2

5 Answers   Mind Tree,


What will be printed as the result of the operation below: #include<..> int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%d\n",x); x++; changevalue(x); printf("Second output:%d\n",x); modifyvalue(); printf("Third output:%d\n",x); }

2 Answers  


Categories