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
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 |
for(;;) printf("C language") What is out put of above??
2 Answers Practical Viva Questions,
Write a program to print numbers from 1 to 100 without using loop in c?
Write a program to generate random numbers in c?
void main() { int x=25,y=32; clrscr(); x=x++ + y++; y=++x + ++y; printf("%d%d",x,y); }
CopyBits(x,p,n,y) copy n LSBs from y to x starting LSB at 'p'th position.
Write a program to reverse a given number in c language?
What is the output of following program ? int main() { int x = 5; printf("%d %d %d\n", x, x << 2, x >> 2); }
C passes By value or By reference?
5 Answers Geometric Software, Infosys,
What is the use of a semicolon (;) at the end of every program statement?
What is the output for the below program? void main() { float me=1.1; double you=1.1; if(me==you) printf("love c"); else printf("know c"); }
Write a program to interchange two variables without using the third variable?
17 Answers Accenture, College School Exams Tests, Infotech,
a.One Cannot Take the address of a Bit Field b.bit fields cannot be arrayed c.Bit-Fields are machine Dependant d.Bit-fields cannot be declared as static Which of the Following Statements are true w.r.t Bit-Fields A)a,b&c B)Only a & b C)Only c D)All
3 Answers Accenture, Digg.com,