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
What is the difference between Printf(..) and sprint(...) ?
Can you write the function prototype, definition and mention the other requirements.
What is c language used for?
Where define directive used?
what is the function of pragma directive in c?
What is extern variable in c with example?
How can I sort a linked list?
Which is an example of a structural homology?
Write a program of advanced Fibonacci series.
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
Can you please compare array with pointer?
What does calloc stand for?
How can this be legal c?
What is identifier in c?
In which layer of the network datastructure format change is done