char *someFun1()

{

char temp[ ] = “string";

return temp;

}

char *someFun2()

{

char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};

return temp;

}

int main()

{

puts(someFun1());

puts(someFun2());

}

Answer Posted / susie

Answer :

Garbage values.

Explanation:

Both the functions suffer from the problem of dangling
pointers. In someFun1() temp is a character array and so the
space for it is allocated in heap and is initialized with
character string “string”. This is created dynamically as
the function is called, so is also deleted dynamically on
exiting the function so the string data is not available in
the calling function main() leading to print some garbage
values. The function someFun2() also suffers from the same
problem but the problem can be easily identified in this case.

Is This Answer Correct ?    11 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to palindrom string in c language?

9779


Sir... please give some important coding questions asked by product companies..

2019


Cluster head selection in Wireless Sensor Network using C programming language.

3375


What is full form of PEPSI

2116


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1293






Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

4071


How can you relate the function with the structure? Explain with an appropriate example.

3126


write a program for area of circumference of shapes

2225


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

2351


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2497


why nlogn is the lower limit of any sort algorithm?

2541


Write a program to model an exploding firecracker in the xy plane using a particle system

3866


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

3073


write a simple calculator c program to perform addition, subtraction, mul and div.

3384


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

729