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



what will be the result of the following program ? char *gxxx() ..

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

what will be the result of the following program ? char *gxxx() ..

Answer / abhiraj

oldstring

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More C Interview Questions

Simplify the program segment if X = B then C ← true else C ← false

0 Answers  


How to add two numbers without using semicolon at runtime

2 Answers  


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL

0 Answers  


What does the error message "DGROUP exceeds 64K" mean?

0 Answers   Celstream,


Why c is a procedural language?

0 Answers  






Explain goto?

0 Answers  


How can a process change an environment variable in its caller?

0 Answers  


How can I dynamically allocate arrays?

0 Answers  


write a c program to find the square of a 5 digit number and print the result.

5 Answers   Accenture, Sasken, Vimukti Technologies,


hat is a pointer?

4 Answers   Assurgent,


What is structure in c definition?

0 Answers  


write a progam to display the factors of a given number and disply how many prime numbers are there?

2 Answers  


Categories