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
Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent
What is a dynamic array in c?
What is c system32 taskhostw exe?
c language interview questions & answer
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
Why is c faster?
Can we access the array using a pointer in c language?
Does sprintf put null character?
define string ?
Is there anything like an ifdef for typedefs?
program to find error in linklist.(i.e find whether any node point wrongly to previous nodes instead of next node)
What is wrong in this statement? scanf(ā%dā,whatnumber);
What is sizeof return in c?
What are the types of c language?