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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between Printf(..) and sprint(...) ?

791


Can you write the function prototype, definition and mention the other requirements.

664


What is c language used for?

560


Where define directive used?

607


what is the function of pragma directive in c?

627






What is extern variable in c with example?

539


How can I sort a linked list?

636


Which is an example of a structural homology?

786


Write a program of advanced Fibonacci series.

710


a program that performs some preliminary processing in C, it acts upon certain directives that will affect how the compiler does its work a) compiler b) loader c) directive d) preprocessor

642


Can you please compare array with pointer?

618


What does calloc stand for?

652


How can this be legal c?

655


What is identifier in c?

547


In which layer of the network datastructure format change is done

1435