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 are the advantages of using macro in c language?
hi, which software companys will take,if d candidate's % is jst 55%?
Do array subscripts always start with zero?
What is the difference between procedural and functional programming?
What are linked lists in c?
Why #include is used in c language?
please can any one suggest me best useful video tutorials on c i am science graduate.please help me.u can email me to sas29@in.com
How many levels of pointers have?
What does *p++ do? What does it point to?
List some of the static data structures in C?
What is extern c used for?
What is the difference between array and pointer in c?
What is the role of this pointer?
Write a program to check palindrome number in c programming?
Explain how can you tell whether two strings are the same?