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 |
Simplify the program segment if X = B then C ← true else C ← false
How to add two numbers without using semicolon at runtime
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
What does the error message "DGROUP exceeds 64K" mean?
Why c is a procedural language?
Explain goto?
How can a process change an environment variable in its caller?
How can I dynamically allocate arrays?
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?
What is structure in c definition?
write a progam to display the factors of a given number and disply how many prime numbers are there?