ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
oldstring
 
Is This Answer Correct ?    0 Yes 0 No
Abhiraj
 
  Re: 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
# 2
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 ?    1 Yes 0 No
Jaya Prakash
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)........1(for values of n greater than or equal to 1 and n!=1(for n=0) Perform the following 1.write a c program that reads a non-negative integer and computes and prints its factorial. 2. write a C program that estimates the value of the mathematical constant e by using the formula: e=1+1/!+1/2!+1/3!+.... 3. write a c program the computes the value ex by using the formula ex=1+x/1!+xsquare/2!+xcube/3!+.... Ignou1
# define prod(a,b)=a*b main() { int x=2; int y=3; printf("%d",prod(x+2,y-10)); } the output of the program is a.8 b.6 c.7 d.none TCS5
post new interiew question and aptitude test papers  1
Average of a couple 10 years ago was 25. The average remains same after having a child and twins after 3 years. What is the present age of the first child IBM9
write a C code To reverse a linked list Motorola1
study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above Accenture12
how to find out the inorder successor of a node in a tree?? TCS2
which of the function operator cannot be over loaded a) <= b)?: c)== d)* HCL4
When you call malloc() to allocate memory for a local pointer, do you have to explicitly free() it?  2
can i know the source code for reversing a linked list with out using a temporary variable? Honeywell3
How the C program can be compiled? HP6
How can I call a function, given its name as a string? ABC-Telecom1
What is structure padding & expalain wid example what is bit wise structure?  1
implement general tree using link list Wipro1
hello friends what do u mean by BUS ERROR i got this error while i am doing my program in DATA STRUCTURES Wipro2
How can I make a program in c to print 'Hello' without using semicolon in the code? C-DAC3
difference between my-strcpy and strcpy ? Geometric-Software3
what is the difference between declaration ,defenetion and initialization of a variable? LG-Soft4
what is object oriental programing?  1
if a person is buying coconuts of Rs10,and then sell that coconuts of Rs9,with the loss of one rupee.After that the person became a millaniore.how? Wipro5
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com